withSentryRouter.tsx 1.0 KB

12345678910111213141516171819202122232425262728
  1. // eslint-disable-next-line no-restricted-imports
  2. import {withRouter, WithRouterProps} from 'react-router';
  3. import {customerDomain, usingCustomerDomain} from 'sentry/constants';
  4. /**
  5. * withSentryRouter is a higher-order component (HOC) that wraps withRouter, and implicitly injects the current customer
  6. * domain as the orgId parameter. This only happens if a customer domain is currently being used.
  7. *
  8. * Since withRouter() is discouraged from being used on new React components, we would use withSentryRouter() on
  9. * pre-existing React components.
  10. */
  11. function withSentryRouter<P extends WithRouterProps>(
  12. WrappedComponent: React.ComponentType<P>
  13. ) {
  14. function WithSentryRouterWrapper(props: P) {
  15. const {params} = props;
  16. if (usingCustomerDomain) {
  17. const newParams = {...params, orgId: customerDomain};
  18. return <WrappedComponent {...props} params={newParams} />;
  19. }
  20. return <WrappedComponent {...props} />;
  21. }
  22. return withRouter(WithSentryRouterWrapper);
  23. }
  24. export default withSentryRouter;