withProjects.tsx 882 B

1234567891011121314151617181920212223242526272829303132
  1. import * as React from 'react';
  2. import {Project} from 'sentry/types';
  3. import getDisplayName from 'sentry/utils/getDisplayName';
  4. import useProjects from 'sentry/utils/useProjects';
  5. type InjectedProjectsProps = {
  6. projects: Project[];
  7. loadingProjects?: boolean;
  8. };
  9. /**
  10. * Higher order component that uses ProjectsStore and provides a list of projects
  11. */
  12. function withProjects<P extends InjectedProjectsProps>(
  13. WrappedComponent: React.ComponentType<P>
  14. ) {
  15. type Props = Omit<P, keyof InjectedProjectsProps>;
  16. const Wrapper: React.FC<Props> = props => {
  17. const {projects, initiallyLoaded} = useProjects();
  18. const loadingProjects = !initiallyLoaded;
  19. return <WrappedComponent {...(props as P)} {...{projects, loadingProjects}} />;
  20. };
  21. Wrapper.displayName = `withProjects(${getDisplayName(WrappedComponent)})`;
  22. return Wrapper;
  23. }
  24. export default withProjects;