withProjects.tsx 849 B

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