docs.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import type {AvatarProject} from 'sentry/types';
  2. const platforms = [
  3. 'dotnet',
  4. 'android',
  5. 'apple',
  6. 'dart',
  7. 'elixir',
  8. 'flutter',
  9. 'go',
  10. 'java',
  11. 'javascript',
  12. 'native',
  13. 'node',
  14. 'perl',
  15. 'php',
  16. 'powershell',
  17. 'python',
  18. 'react-native',
  19. 'ruby',
  20. 'rust',
  21. 'unity',
  22. ] as const;
  23. export type DocPlatform = (typeof platforms)[number];
  24. const performancePlatforms: DocPlatform[] = [
  25. 'dotnet',
  26. 'android',
  27. 'apple',
  28. 'go',
  29. 'java',
  30. 'javascript',
  31. 'node',
  32. 'php',
  33. 'powershell',
  34. 'python',
  35. 'react-native',
  36. 'ruby',
  37. ];
  38. function validDocPlatform(platform: any): platform is DocPlatform {
  39. return platforms.includes(platform);
  40. }
  41. export function getDocsPlatform(
  42. platform: string,
  43. performanceOnly: boolean
  44. ): DocPlatform | null {
  45. // react-native is the only platform that has a dash, and supports performance so we can skip that check
  46. if (platform === 'react-native') {
  47. return 'react-native';
  48. }
  49. const index = platform.indexOf('-');
  50. const prefix = index >= 0 ? platform.substring(0, index) : platform;
  51. if (validDocPlatform(prefix)) {
  52. const validPerformancePrefix = performancePlatforms.includes(prefix);
  53. if ((performanceOnly && validPerformancePrefix) || !performanceOnly) {
  54. return prefix;
  55. }
  56. }
  57. // can't find a matching docs platform
  58. return null;
  59. }
  60. export function getConfigurePerformanceDocsLink(
  61. project: AvatarProject | undefined
  62. ): string | null {
  63. const platform = project?.platform ?? null;
  64. const docsPlatform = platform ? getDocsPlatform(platform, true) : null;
  65. return docsPlatform === null
  66. ? null // this platform does not support performance
  67. : `https://docs.sentry.io/platforms/${docsPlatform}/tracing/`;
  68. }
  69. export function getConfigureIntegrationsDocsLink(
  70. project: AvatarProject | undefined
  71. ): string | null {
  72. const platform = project?.platform ?? null;
  73. const docsPlatform = platform ? getDocsPlatform(platform, true) : null;
  74. return docsPlatform === null
  75. ? null // this platform does not support performance
  76. : `https://docs.sentry.io/platforms/${docsPlatform}/configuration/integrations`;
  77. }