issuesReplayCountProvider.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {Fragment, ReactNode} from 'react';
  2. import ReplayCountContext from 'sentry/components/replays/replayCountContext';
  3. import useReplaysCount from 'sentry/components/replays/useReplaysCount';
  4. import type {Organization} from 'sentry/types';
  5. import useOrganization from 'sentry/utils/useOrganization';
  6. type Props = {
  7. children: ReactNode;
  8. groupIds: string[];
  9. };
  10. /**
  11. * Component to make it easier to query for replay counts against a list of groups
  12. * that exist across many projects.
  13. *
  14. * Later on when you want to read the fetched data:
  15. * ```
  16. * import ReplayCountContext from 'sentry/components/replays/replayCountContext';
  17. * const count = useContext(ReplayCountContext)[groupId];
  18. * ```
  19. */
  20. export default function IssuesReplayCountProvider({children, groupIds}: Props) {
  21. const organization = useOrganization();
  22. const hasSessionReplay = organization.features.includes('session-replay');
  23. if (hasSessionReplay) {
  24. return (
  25. <Provider organization={organization} groupIds={groupIds}>
  26. {children}
  27. </Provider>
  28. );
  29. }
  30. return <Fragment>{children}</Fragment>;
  31. }
  32. function Provider({
  33. children,
  34. groupIds,
  35. organization,
  36. }: Props & {organization: Organization}) {
  37. const counts = useReplaysCount({
  38. groupIds,
  39. organization,
  40. });
  41. return (
  42. <ReplayCountContext.Provider value={counts}>{children}</ReplayCountContext.Provider>
  43. );
  44. }