replayIdCountProvider.tsx 840 B

1234567891011121314151617181920212223242526272829
  1. import {ReactNode, ReactText, useMemo} 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 = useMemo(() => replayIds?.map(String)?.filter(Boolean) || [], [replayIds]);
  15. const counts = useReplaysCount({
  16. replayIds: unique(ids),
  17. organization,
  18. });
  19. return (
  20. <ReplayCountContext.Provider value={counts}>{children}</ReplayCountContext.Provider>
  21. );
  22. }
  23. export default ReplayIdCountProvider;