util.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import partition from 'lodash/partition';
  2. import {PlatformKey} from 'sentry/data/platformCategories';
  3. import {Project} from 'sentry/types/project';
  4. import {
  5. getDocsPlatformSDKForPlatform,
  6. SupportedProfilingPlatformSDK,
  7. } from 'sentry/utils/profiling/platforms';
  8. export const profilingOnboardingDocKeys = [
  9. '0-alert',
  10. '1-install',
  11. '2-configure-performance',
  12. '3-configure-profiling',
  13. '4-upload',
  14. ] as const;
  15. type ProfilingOnboardingDocKeys = (typeof profilingOnboardingDocKeys)[number];
  16. export const supportedPlatformExpectedDocKeys: Record<
  17. SupportedProfilingPlatformSDK,
  18. ProfilingOnboardingDocKeys[]
  19. > = {
  20. android: ['1-install', '2-configure-performance', '3-configure-profiling', '4-upload'],
  21. 'apple-ios': [
  22. '1-install',
  23. '2-configure-performance',
  24. '3-configure-profiling',
  25. '4-upload',
  26. ],
  27. node: ['0-alert', '1-install', '2-configure-performance', '3-configure-profiling'],
  28. python: ['0-alert', '1-install', '2-configure-performance', '3-configure-profiling'],
  29. php: ['0-alert', '1-install', '2-configure-performance', '3-configure-profiling'],
  30. rust: ['0-alert', '1-install', '2-configure-performance', '3-configure-profiling'],
  31. };
  32. function makeDocKey(platformId: PlatformKey, key: string) {
  33. return `${platformId}-profiling-onboarding-${key}`;
  34. }
  35. type DocKeyMap = Record<(typeof profilingOnboardingDocKeys)[number], string>;
  36. export function makeDocKeyMap(platformId: PlatformKey | undefined) {
  37. const docsPlatform = getDocsPlatformSDKForPlatform(platformId);
  38. if (!platformId || !docsPlatform) {
  39. return null;
  40. }
  41. const expectedDocKeys: ProfilingOnboardingDocKeys[] =
  42. supportedPlatformExpectedDocKeys[docsPlatform];
  43. return expectedDocKeys.reduce((acc: DocKeyMap, key) => {
  44. acc[key] = makeDocKey(docsPlatform, key);
  45. return acc;
  46. }, {} as DocKeyMap);
  47. }
  48. export function splitProjectsByProfilingSupport(projects: Project[]): {
  49. supported: Project[];
  50. unsupported: Project[];
  51. } {
  52. const [supported, unsupported] = partition(
  53. projects,
  54. project => project.platform && getDocsPlatformSDKForPlatform(project.platform)
  55. );
  56. return {supported, unsupported};
  57. }