withOrganization.tsx 938 B

1234567891011121314151617181920212223242526272829303132333435
  1. import * as React from 'react';
  2. import SentryTypes from 'sentry/sentryTypes';
  3. import {Organization} from 'sentry/types';
  4. import getDisplayName from 'sentry/utils/getDisplayName';
  5. type InjectedOrganizationProps = {
  6. organization?: Organization;
  7. };
  8. const withOrganization = <P extends InjectedOrganizationProps>(
  9. WrappedComponent: React.ComponentType<P>
  10. ) =>
  11. class extends React.Component<
  12. Omit<P, keyof InjectedOrganizationProps> & InjectedOrganizationProps
  13. > {
  14. static displayName = `withOrganization(${getDisplayName(WrappedComponent)})`;
  15. static contextTypes = {
  16. organization: SentryTypes.Organization,
  17. };
  18. render() {
  19. const {organization, ...props} = this.props;
  20. return (
  21. <WrappedComponent
  22. {...({
  23. organization: organization ?? this.context.organization,
  24. ...props,
  25. } as P)}
  26. />
  27. );
  28. }
  29. };
  30. export default withOrganization;