useDenylistedProjects.tsx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import useProjects from 'sentry/utils/useProjects';
  2. interface Options {
  3. projectId?: string[];
  4. }
  5. /**
  6. * Returns a list of projects that are not eligible for span metrics
  7. * because they were denylisted.
  8. *
  9. * @param options Additional options
  10. * @param options.projectId List of project IDs to check against. If omitted, checks all organization projects
  11. * @returns List of projects
  12. */
  13. export function useDenylistedProjects(options: Options = {}) {
  14. const {projects, fetching} = useProjects();
  15. const {projectId = []} = options;
  16. const shouldCheckAllProjects = projectId.length === 0 || projectId.includes('-1');
  17. const projectsToCheck = shouldCheckAllProjects
  18. ? projects
  19. : projects.filter(project => projectId.includes(project.id.toString()));
  20. const denylistedProjects = projectsToCheck
  21. .filter(project => {
  22. return !project.features.includes('span-metrics-extraction');
  23. })
  24. .filter((item): item is NonNullable<typeof item> => Boolean(item));
  25. return {
  26. projects: denylistedProjects,
  27. isFetching: fetching,
  28. };
  29. }