withOrganization.tsx 855 B

123456789101112131415161718192021222324252627282930
  1. import type {Organization} from 'sentry/types/organization';
  2. import getDisplayName from 'sentry/utils/getDisplayName';
  3. import useOrganization from './useOrganization';
  4. type InjectedOrganizationProps = {
  5. organization?: Organization;
  6. organizationAllowNull?: undefined | true;
  7. };
  8. function withOrganization<P extends InjectedOrganizationProps>(
  9. WrappedComponent: React.ComponentType<P>
  10. ) {
  11. type Props = Omit<P, keyof InjectedOrganizationProps> &
  12. Partial<InjectedOrganizationProps>;
  13. function Wrapper(props: Props) {
  14. const organization = useOrganization({allowNull: props.organizationAllowNull});
  15. const allProps = {organization, ...props} as P;
  16. return <WrappedComponent {...allProps} />;
  17. }
  18. Wrapper.displayName = `withOrganization(${getDisplayName(WrappedComponent)})`;
  19. return Wrapper;
  20. }
  21. export default withOrganization;