withProject.tsx 888 B

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