projectSettingsLayout.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {cloneElement, isValidElement} from 'react';
  2. import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  3. import type {Organization} from 'sentry/types/organization';
  4. import type {Project} from 'sentry/types/project';
  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. <SettingsLayout
  30. params={params}
  31. routes={routes}
  32. {...props}
  33. renderNavigation={() => <ProjectSettingsNavigation organization={organization} />}
  34. >
  35. {children && isValidElement(children)
  36. ? cloneElement<any>(children, {organization, project})
  37. : children}
  38. </SettingsLayout>
  39. );
  40. }
  41. function ProjectSettingsLayout({organization, params, ...props}: Props) {
  42. return (
  43. <ProjectContext projectSlug={params.projectId}>
  44. {({project}) => (
  45. <InnerProjectSettingsLayout {...{params, project, organization, ...props}} />
  46. )}
  47. </ProjectContext>
  48. );
  49. }
  50. export default withOrganization(ProjectSettingsLayout);