inlineDocs.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as Sentry from '@sentry/react';
  4. import {loadDocs} from 'sentry/actionCreators/projects';
  5. import {Client} from 'sentry/api';
  6. import ExternalLink from 'sentry/components/links/externalLink';
  7. import LoadingIndicator from 'sentry/components/loadingIndicator';
  8. import {PlatformKey} from 'sentry/data/platformCategories';
  9. import {t, tct} from 'sentry/locale';
  10. import withApi from 'sentry/utils/withApi';
  11. type Props = {
  12. api: Client;
  13. platform: string;
  14. projectSlug: string;
  15. orgSlug: string;
  16. };
  17. type State = {
  18. loading: boolean;
  19. html: string | undefined;
  20. link: string | undefined;
  21. };
  22. class InlineDocs extends Component<Props, State> {
  23. state: State = {
  24. loading: true,
  25. html: undefined,
  26. link: undefined,
  27. };
  28. componentDidMount() {
  29. this.fetchData();
  30. }
  31. fetchData = async () => {
  32. const {platform, api, orgSlug, projectSlug} = this.props;
  33. if (!platform) {
  34. return;
  35. }
  36. this.setState({loading: true});
  37. let tracingPlatform: PlatformKey;
  38. switch (platform) {
  39. case 'sentry.python': {
  40. tracingPlatform = 'python-tracing';
  41. break;
  42. }
  43. case 'sentry.javascript.node': {
  44. tracingPlatform = 'node-tracing';
  45. break;
  46. }
  47. case 'sentry.javascript.react-native': {
  48. tracingPlatform = 'react-native-tracing';
  49. break;
  50. }
  51. default: {
  52. this.setState({loading: false});
  53. return;
  54. }
  55. }
  56. try {
  57. const {html, link} = await loadDocs(api, orgSlug, projectSlug, tracingPlatform);
  58. this.setState({html, link});
  59. } catch (error) {
  60. Sentry.captureException(error);
  61. this.setState({html: undefined, link: undefined});
  62. }
  63. this.setState({loading: false});
  64. };
  65. render() {
  66. const {platform} = this.props;
  67. if (!platform) {
  68. return null;
  69. }
  70. if (this.state.loading) {
  71. return (
  72. <div>
  73. <LoadingIndicator />
  74. </div>
  75. );
  76. }
  77. if (this.state.html) {
  78. return (
  79. <div>
  80. <h4>{t('Requires Manual Instrumentation')}</h4>
  81. <DocumentationWrapper dangerouslySetInnerHTML={{__html: this.state.html}} />
  82. <p>
  83. {tct(
  84. `For in-depth instructions on setting up tracing, view [docLink:our documentation].`,
  85. {
  86. docLink: <a href={this.state.link} />,
  87. }
  88. )}
  89. </p>
  90. </div>
  91. );
  92. }
  93. return (
  94. <div>
  95. <h4>{t('Requires Manual Instrumentation')}</h4>
  96. <p>
  97. {tct(
  98. `To manually instrument certain regions of your code, view [docLink:our documentation].`,
  99. {
  100. docLink: (
  101. <ExternalLink href="https://docs.sentry.io/product/performance/getting-started/" />
  102. ),
  103. }
  104. )}
  105. </p>
  106. </div>
  107. );
  108. }
  109. }
  110. const DocumentationWrapper = styled('div')`
  111. p {
  112. line-height: 1.5;
  113. }
  114. pre {
  115. word-break: break-all;
  116. white-space: pre-wrap;
  117. }
  118. `;
  119. export default withApi(InlineDocs);