sdkDocumentation.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {useEffect, useState} from 'react';
  2. import LoadingIndicator from 'sentry/components/loadingIndicator';
  3. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  4. import {PlatformKey} from 'sentry/data/platformCategories';
  5. import type {Organization, PlatformIntegration, Project, ProjectKey} from 'sentry/types';
  6. import {useApiQuery} from 'sentry/utils/queryClient';
  7. // Documents already migrated from sentry-docs to main sentry repository
  8. export const migratedDocs = [
  9. 'javascript-react',
  10. 'javascript-remix',
  11. 'javascript-angular',
  12. 'javascript-vue',
  13. 'javascript-gatsby',
  14. 'javascript-ember',
  15. 'javascript-svelte',
  16. 'javascript-sveltekit',
  17. 'javascript-nextjs',
  18. 'javascript',
  19. 'python-django',
  20. 'python',
  21. 'python-flask',
  22. 'python-wsgi',
  23. 'python-tryton',
  24. 'python-tornado',
  25. 'python-starlette',
  26. 'python-serverless',
  27. 'python-sanic',
  28. 'python-quart',
  29. 'python-pyramid',
  30. 'python-pylons',
  31. 'python-gcpfunctions',
  32. 'python-falcon',
  33. 'python-chalice',
  34. 'python-bottle',
  35. 'python-fastapi',
  36. 'python-asgi',
  37. 'python-aiohttp',
  38. 'python-awslambda',
  39. 'dotnet',
  40. 'dotnet-aspnetcore',
  41. 'dotnet-awslambda',
  42. 'dotnet-gcpfunctions',
  43. 'dotnet-maui',
  44. 'dotnet-uwp',
  45. 'dotnet-winforms',
  46. 'dotnet-wpf',
  47. 'dotnet-xamarin',
  48. 'dotnet-aspnet',
  49. 'react-native',
  50. 'java',
  51. 'java-spring-boot',
  52. 'java-logback',
  53. 'java-log4j2',
  54. 'java-spring',
  55. 'php',
  56. 'php-laravel',
  57. 'php-symfony',
  58. 'go',
  59. 'rust',
  60. 'minidump',
  61. 'native',
  62. 'native-qt',
  63. 'ruby',
  64. 'ruby-rails',
  65. 'ruby-rack',
  66. 'kotlin',
  67. 'node',
  68. 'node-awslambda',
  69. 'node-azurefunctions',
  70. 'node-connect',
  71. 'node-gcpfunctions',
  72. 'node-express',
  73. 'node-serverlesscloud',
  74. 'electron',
  75. 'elixir',
  76. ];
  77. type SdkDocumentationProps = {
  78. activeProductSelection: ProductSolution[];
  79. organization: Organization;
  80. platform: PlatformIntegration | null;
  81. projectSlug: Project['slug'];
  82. newOrg?: boolean;
  83. projectId?: Project['id'];
  84. };
  85. export type ModuleProps = {
  86. dsn: string;
  87. activeProductSelection?: ProductSolution[];
  88. newOrg?: boolean;
  89. organization?: Organization;
  90. platformKey?: PlatformKey;
  91. projectId?: Project['id'];
  92. };
  93. // Loads the component containing the documentation for the specified platform
  94. export function SdkDocumentation({
  95. platform,
  96. projectSlug,
  97. activeProductSelection,
  98. newOrg,
  99. organization,
  100. projectId,
  101. }: SdkDocumentationProps) {
  102. const [module, setModule] = useState<null | {
  103. default: React.ComponentType<ModuleProps>;
  104. }>(null);
  105. const platformPath =
  106. platform?.type === 'framework'
  107. ? platform.language === 'minidump'
  108. ? `minidump/minidump`
  109. : platform?.id === 'native-qt'
  110. ? `native/native-qt`
  111. : platform?.id.replace(`${platform.language}-`, `${platform.language}/`)
  112. : `${platform?.language}/${platform?.id}`;
  113. const {
  114. data: projectKeys = [],
  115. isError: projectKeysIsError,
  116. isLoading: projectKeysIsLoading,
  117. } = useApiQuery<ProjectKey[]>([`/projects/${organization.slug}/${projectSlug}/keys/`], {
  118. staleTime: Infinity,
  119. });
  120. useEffect(() => {
  121. if (projectKeysIsError || projectKeysIsLoading) {
  122. return;
  123. }
  124. async function getGettingStartedDoc() {
  125. const mod = await import(
  126. /* webpackExclude: /.spec/ */
  127. `sentry/gettingStartedDocs/${platformPath}`
  128. );
  129. setModule(mod);
  130. }
  131. getGettingStartedDoc();
  132. }, [platformPath, projectKeysIsError, projectKeysIsLoading, projectKeys]);
  133. if (!module) {
  134. return <LoadingIndicator />;
  135. }
  136. const {default: GettingStartedDoc} = module;
  137. return (
  138. <GettingStartedDoc
  139. dsn={projectKeys[0].dsn.public}
  140. activeProductSelection={activeProductSelection}
  141. newOrg={newOrg}
  142. platformKey={platform?.id}
  143. organization={organization}
  144. projectId={projectId}
  145. />
  146. );
  147. }