withPageFilters.tsx 1015 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import {PageFilters} from 'sentry/types';
  2. import getDisplayName from 'sentry/utils/getDisplayName';
  3. import usePageFilters from './usePageFilters';
  4. type InjectedPageFiltersProps = {
  5. isGlobalSelectionReady?: boolean;
  6. selection?: PageFilters;
  7. };
  8. /**
  9. * Higher order component that uses PageFiltersStore and provides the active
  10. * project
  11. */
  12. function withPageFilters<P extends InjectedPageFiltersProps>(
  13. WrappedComponent: React.ComponentType<P>
  14. ) {
  15. type Props = Omit<P, keyof InjectedPageFiltersProps> & InjectedPageFiltersProps;
  16. const WithPageFilters: React.FC<Props> = props => {
  17. const {selection, isReady: isGlobalSelectionReady} = usePageFilters();
  18. const selectionProps = {
  19. selection,
  20. isGlobalSelectionReady,
  21. };
  22. return <WrappedComponent {...selectionProps} {...(props as P)} />;
  23. };
  24. const displayName = getDisplayName(WrappedComponent);
  25. WithPageFilters.displayName = `withPageFilters(${displayName})`;
  26. return WithPageFilters;
  27. }
  28. export default withPageFilters;