index.tsx 1.1 KB

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