pipelineView.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {useEffect} from 'react';
  2. import {createMemoryHistory, Route, Router, RouterContext} from 'react-router';
  3. import Indicators from 'sentry/components/indicators';
  4. import {ThemeAndStyleProvider} from 'sentry/components/themeAndStyleProvider';
  5. import {RouteContext} from 'sentry/views/routeContext';
  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. /**
  21. * This component is a wrapper for specific pipeline views for integrations
  22. */
  23. function PipelineView({pipelineName, ...props}: Props) {
  24. const mapping = pipelineMapper[pipelineName];
  25. if (!mapping) {
  26. throw new Error(`Invalid pipeline name ${pipelineName}`);
  27. }
  28. const [Component, title] = mapping;
  29. // Set the page title
  30. useEffect(() => void (document.title = title), [title]);
  31. const memoryHistory = createMemoryHistory();
  32. memoryHistory.push('/');
  33. return (
  34. <Router
  35. history={memoryHistory}
  36. render={renderProps => {
  37. return (
  38. <ThemeAndStyleProvider>
  39. <Indicators className="indicators-container" />
  40. <RouteContext.Provider value={renderProps}>
  41. <RouterContext {...renderProps} />
  42. </RouteContext.Provider>
  43. </ThemeAndStyleProvider>
  44. );
  45. }}
  46. >
  47. <Route path="*" component={() => <Component {...props} />} props={props} />
  48. </Router>
  49. );
  50. }
  51. export default PipelineView;