platformOrIntegration.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {useState} from 'react';
  2. import {OnboardingContextProvider} from 'sentry/components/onboarding/onboardingContext';
  3. import allPlatforms from 'sentry/data/platforms';
  4. import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  5. import {platformToIntegrationMap} from 'sentry/utils/integrationUtil';
  6. import useOrganization from 'sentry/utils/useOrganization';
  7. import useProjects from 'sentry/utils/useProjects';
  8. import GettingStarted from './gettingStarted';
  9. import {ProjectInstallPlatform} from './platform';
  10. import {PlatformIntegrationSetup} from './platformIntegrationSetup';
  11. type Props = RouteComponentProps<{projectId: string}, {}>;
  12. function PlatformOrIntegration({params}: Props) {
  13. const organization = useOrganization();
  14. const [integrationUseManualSetup, setIntegrationUseManualSetup] = useState(false);
  15. const {projects, initiallyLoaded} = useProjects({
  16. slugs: [params.projectId],
  17. orgId: organization.slug,
  18. });
  19. const loadingProjects = !initiallyLoaded;
  20. const project = !loadingProjects
  21. ? projects.find(proj => proj.slug === params.projectId)
  22. : undefined;
  23. const currentPlatformKey = project?.platform ?? 'other';
  24. const currentPlatform = allPlatforms.find(p => p.id === currentPlatformKey);
  25. const integrationSlug: string | undefined =
  26. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  27. platformToIntegrationMap[currentPlatformKey];
  28. const showIntegrationOnboarding = integrationSlug && !integrationUseManualSetup;
  29. if (showIntegrationOnboarding) {
  30. return (
  31. <PlatformIntegrationSetup
  32. integrationSlug={integrationSlug}
  33. onClickManualSetup={() => setIntegrationUseManualSetup(true)}
  34. project={project}
  35. platform={currentPlatform}
  36. loading={loadingProjects}
  37. />
  38. );
  39. }
  40. return (
  41. <OnboardingContextProvider>
  42. <GettingStarted withPadding>
  43. <ProjectInstallPlatform
  44. project={project}
  45. loading={loadingProjects}
  46. platform={currentPlatform}
  47. currentPlatformKey={currentPlatformKey}
  48. />
  49. </GettingStarted>
  50. </OnboardingContextProvider>
  51. );
  52. }
  53. export default PlatformOrIntegration;