useErrorCountPerProject.tsx 838 B

1234567891011121314151617181920212223242526
  1. import {useMemo} from 'react';
  2. import countBy from 'lodash/countBy';
  3. import useProjects from 'sentry/utils/useProjects';
  4. import type {ReplayError, ReplayRecord} from 'sentry/views/replays/types';
  5. type Props = {
  6. replayErrors: ReplayError[];
  7. replayRecord: ReplayRecord;
  8. };
  9. export default function useErrorCountByProject({replayErrors, replayRecord}: Props) {
  10. const {projects} = useProjects();
  11. return useMemo(() => {
  12. return (
  13. Object.entries(countBy(replayErrors, 'project.name'))
  14. .map(([projectSlug, count]) => {
  15. const project = projects.find(p => p.slug === projectSlug);
  16. return {project, count};
  17. })
  18. // sort to prioritize the replay errors first
  19. .sort(a => (a.project?.id !== replayRecord.project_id ? 1 : -1))
  20. );
  21. }, [projects, replayErrors, replayRecord]);
  22. }