useSelectedProjects.tsx 593 B

12345678910111213141516171819
  1. import {useMemo} from 'react';
  2. import usePageFilters from 'sentry/utils/usePageFilters';
  3. import useProjects from 'sentry/utils/useProjects';
  4. export function useSelectedProjects() {
  5. const {selection} = usePageFilters();
  6. const {projects} = useProjects();
  7. return useMemo(() => {
  8. if (selection.projects.length === 0) {
  9. return projects.filter(project => project.isMember);
  10. }
  11. if (selection.projects.includes(-1)) {
  12. return projects;
  13. }
  14. return projects.filter(project => selection.projects.includes(Number(project.id)));
  15. }, [selection.projects, projects]);
  16. }