withPageFilters.tsx 1.1 KB

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