replayIdCountProvider.tsx 823 B

123456789101112131415161718192021222324252627282930
  1. import {ReactNode, ReactText} from 'react';
  2. import ReplayCountContext from 'sentry/components/replays/replayCountContext';
  3. import useReplaysCount from 'sentry/components/replays/useReplaysCount';
  4. import {Organization} from 'sentry/types';
  5. type Props = {
  6. children: ReactNode;
  7. organization: Organization;
  8. replayIds: ReactText[] | string[] | undefined;
  9. };
  10. function unique<T>(arr: T[]) {
  11. return Array.from(new Set(arr));
  12. }
  13. function ReplayIdCountProvider({children, organization, replayIds}: Props) {
  14. const ids = replayIds?.map(String)?.filter(Boolean) || [];
  15. const counts = useReplaysCount({
  16. replayIds: unique(ids),
  17. organization,
  18. projectIds: [],
  19. });
  20. return (
  21. <ReplayCountContext.Provider value={counts}>{children}</ReplayCountContext.Provider>
  22. );
  23. }
  24. export default ReplayIdCountProvider;