projectSettingsLayout.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import {cloneElement, isValidElement} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import * as AppStoreConnectContext from 'sentry/components/projects/appStoreConnectContext';
  4. import {Organization, Project} from 'sentry/types';
  5. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  6. import withOrganization from 'sentry/utils/withOrganization';
  7. import ProjectContext from 'sentry/views/projects/projectContext';
  8. import SettingsLayout from 'sentry/views/settings/components/settingsLayout';
  9. import ProjectSettingsNavigation from 'sentry/views/settings/project/projectSettingsNavigation';
  10. type Props = {
  11. children: React.ReactNode;
  12. organization: Organization;
  13. } & RouteComponentProps<{projectId: string}, {}>;
  14. type InnerProps = Props & {project: Project};
  15. function InnerProjectSettingsLayout({
  16. params,
  17. routes,
  18. project,
  19. organization,
  20. children,
  21. ...props
  22. }: InnerProps) {
  23. // set analytics params for route based analytics
  24. useRouteAnalyticsParams({
  25. project_id: project.id,
  26. project_platform: project.platform,
  27. });
  28. return (
  29. <AppStoreConnectContext.Provider project={project} organization={organization}>
  30. <SettingsLayout
  31. params={params}
  32. routes={routes}
  33. {...props}
  34. renderNavigation={() => <ProjectSettingsNavigation organization={organization} />}
  35. >
  36. {children && isValidElement(children)
  37. ? cloneElement<any>(children, {organization, project})
  38. : children}
  39. </SettingsLayout>
  40. </AppStoreConnectContext.Provider>
  41. );
  42. }
  43. function ProjectSettingsLayout({organization, params, ...props}: Props) {
  44. return (
  45. <ProjectContext projectSlug={params.projectId}>
  46. {({project}) => (
  47. <InnerProjectSettingsLayout {...{params, project, organization, ...props}} />
  48. )}
  49. </ProjectContext>
  50. );
  51. }
  52. export default withOrganization(ProjectSettingsLayout);