index.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import {useEffect, useRef} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import {switchOrganization} from 'sentry/actionCreators/organizations';
  4. import useRouteAnalyticsHookSetup from 'sentry/utils/routeAnalytics/useRouteAnalyticsHookSetup';
  5. import OrganizationContextContainer from 'sentry/views/organizationContextContainer';
  6. import Body from './body';
  7. type Props = RouteComponentProps<{orgId: string}, {}> &
  8. Partial<React.ComponentProps<typeof OrganizationContextContainer>>;
  9. function OrganizationDetails({children, ...props}: Props) {
  10. // Switch organizations when the orgId changes
  11. const orgId = useRef(props.params.orgId);
  12. useRouteAnalyticsHookSetup();
  13. useEffect(() => {
  14. if (props.params.orgId && orgId.current !== props.params.orgId) {
  15. // Only switch on: org1 -> org2
  16. // Not on: undefined -> org1
  17. // Also avoid: org1 -> undefined -> org1
  18. if (orgId.current) {
  19. switchOrganization();
  20. }
  21. orgId.current = props.params.orgId;
  22. }
  23. }, [props.params.orgId]);
  24. return (
  25. <OrganizationContextContainer includeSidebar useLastOrganization {...props}>
  26. <Body>{children}</Body>
  27. </OrganizationContextContainer>
  28. );
  29. }
  30. export default OrganizationDetails;