pipelineView.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {useEffect, useState} from 'react';
  2. import {createMemoryRouter, RouterProvider} from 'react-router-dom';
  3. import Indicators from 'sentry/components/indicators';
  4. import {ThemeAndStyleProvider} from 'sentry/components/themeAndStyleProvider';
  5. import {DANGEROUS_SET_REACT_ROUTER_6_HISTORY} from 'sentry/utils/browserHistory';
  6. import AwsLambdaCloudformation from './awsLambdaCloudformation';
  7. import AwsLambdaFailureDetails from './awsLambdaFailureDetails';
  8. import AwsLambdaFunctionSelect from './awsLambdaFunctionSelect';
  9. import AwsLambdaProjectSelect from './awsLambdaProjectSelect';
  10. const pipelineMapper: Record<string, [React.ComponentType<any>, string]> = {
  11. awsLambdaProjectSelect: [AwsLambdaProjectSelect, 'AWS Lambda Select Project'],
  12. awsLambdaFunctionSelect: [AwsLambdaFunctionSelect, 'AWS Lambda Select Lambdas'],
  13. awsLambdaCloudformation: [AwsLambdaCloudformation, 'AWS Lambda Create Cloudformation'],
  14. awsLambdaFailureDetails: [AwsLambdaFailureDetails, 'AWS Lambda View Failures'],
  15. };
  16. type Props = {
  17. [key: string]: any;
  18. pipelineName: string;
  19. };
  20. function buildRouter(Component: React.ComponentType, props: any) {
  21. const router = createMemoryRouter([
  22. {
  23. path: '*',
  24. element: <Component {...props} props={props} />,
  25. },
  26. ]);
  27. DANGEROUS_SET_REACT_ROUTER_6_HISTORY(router);
  28. return router;
  29. }
  30. /**
  31. * This component is a wrapper for specific pipeline views for integrations
  32. */
  33. function PipelineView({pipelineName, ...props}: Props) {
  34. const mapping = pipelineMapper[pipelineName];
  35. if (!mapping) {
  36. throw new Error(`Invalid pipeline name ${pipelineName}`);
  37. }
  38. const [Component, title] = mapping;
  39. // Set the page title
  40. useEffect(() => void (document.title = title), [title]);
  41. const [router] = useState(() => buildRouter(Component, props));
  42. return (
  43. <ThemeAndStyleProvider>
  44. <Indicators className="indicators-container" />
  45. <RouterProvider router={router} />
  46. </ThemeAndStyleProvider>
  47. );
  48. }
  49. export default PipelineView;