platformOrIntegration.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {useState} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import {OnboardingContextProvider} from 'sentry/components/onboarding/onboardingContext';
  4. import allPlatforms from 'sentry/data/platforms';
  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. platformToIntegrationMap[currentPlatformKey];
  27. const showIntegrationOnboarding = integrationSlug && !integrationUseManualSetup;
  28. if (showIntegrationOnboarding) {
  29. return (
  30. <PlatformIntegrationSetup
  31. integrationSlug={integrationSlug}
  32. onClickManualSetup={() => setIntegrationUseManualSetup(true)}
  33. project={project}
  34. platform={currentPlatform}
  35. loading={loadingProjects}
  36. />
  37. );
  38. }
  39. return (
  40. <OnboardingContextProvider>
  41. <GettingStarted>
  42. <ProjectInstallPlatform
  43. project={project}
  44. loading={loadingProjects}
  45. platform={currentPlatform}
  46. currentPlatformKey={currentPlatformKey}
  47. />
  48. </GettingStarted>
  49. </OnboardingContextProvider>
  50. );
  51. }
  52. export default PlatformOrIntegration;