withSentryAppComponents.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React from 'react';
  2. import createReactClass from 'create-react-class';
  3. import Reflux from 'reflux';
  4. import SentryAppComponentsStore from 'app/stores/sentryAppComponentsStore';
  5. import getDisplayName from 'app/utils/getDisplayName';
  6. // TODO(ts): Update when component type is defined
  7. type Component = {};
  8. type InjectedAppComponentsProps = {
  9. components: Component[];
  10. };
  11. type State = {
  12. components: Component[];
  13. };
  14. type Options = {
  15. componentType?: 'stacktrace-link';
  16. };
  17. const withSentryAppComponents = <P extends InjectedAppComponentsProps>(
  18. WrappedComponent: React.ComponentType<P>,
  19. {componentType}: Options = {}
  20. ) =>
  21. createReactClass<
  22. Omit<P, keyof InjectedAppComponentsProps> & Partial<InjectedAppComponentsProps>,
  23. State
  24. >({
  25. displayName: `withSentryAppComponents(${getDisplayName(WrappedComponent)})`,
  26. mixins: [Reflux.connect(SentryAppComponentsStore, 'components') as any],
  27. render() {
  28. const {components, ...props} = this.props as P;
  29. return (
  30. <WrappedComponent
  31. {...({
  32. components:
  33. components ?? SentryAppComponentsStore.getComponentByType(componentType),
  34. ...props,
  35. } as P)}
  36. />
  37. );
  38. },
  39. });
  40. export default withSentryAppComponents;