useOnboardingProject.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
  2. import type {Project} from 'sentry/types';
  3. import usePageFilters from 'sentry/utils/usePageFilters';
  4. import useProjects from 'sentry/utils/useProjects';
  5. export function useOnboardingProject(): Project | undefined {
  6. const {projects} = useProjects();
  7. const pageFilters = usePageFilters();
  8. if (projects.length === 0) {
  9. return undefined;
  10. }
  11. // Current selection is 'my projects' or 'all projects'
  12. if (
  13. pageFilters.selection.projects.length === 0 ||
  14. pageFilters.selection.projects[0] === ALL_ACCESS_PROJECTS
  15. ) {
  16. const filtered = projects.filter(p => p.firstTransactionEvent === false);
  17. if (filtered.length === projects.length) {
  18. return filtered[0];
  19. }
  20. }
  21. // Any other subset of projects.
  22. const filtered = projects.filter(
  23. p =>
  24. pageFilters.selection.projects.includes(parseInt(p.id, 10)) &&
  25. p.firstTransactionEvent === false
  26. );
  27. if (filtered.length === pageFilters.selection.projects.length) {
  28. return filtered[0];
  29. }
  30. return undefined;
  31. }