useProfileExists.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {useDiscoverQuery} from 'sentry/utils/discover/discoverQuery';
  2. import EventView from 'sentry/utils/discover/eventView';
  3. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import useOrganization from 'sentry/utils/useOrganization';
  6. import usePageFilters from 'sentry/utils/usePageFilters';
  7. /**
  8. * Query results for whether a given replayId exists in the database (not deleted, etc)
  9. */
  10. export default function useProfileExists(ids: string[]) {
  11. const organization = useOrganization();
  12. const pageFilters = usePageFilters();
  13. const location = useLocation();
  14. const eventView = EventView.fromNewQueryWithPageFilters(
  15. {
  16. fields: ['profile.id'],
  17. name: 'Web Vitals',
  18. query: `profile.id:[${ids.join(',')}]`,
  19. version: 2,
  20. dataset: DiscoverDatasets.DISCOVER,
  21. },
  22. pageFilters.selection
  23. );
  24. const {data} = useDiscoverQuery({
  25. eventView,
  26. location,
  27. orgSlug: organization.slug,
  28. limit: 100,
  29. options: {
  30. enabled: !!ids.length,
  31. },
  32. });
  33. const profileExists = (id: string) => {
  34. if (!ids.length) {
  35. return false;
  36. }
  37. return !!data?.data?.some(row => row['profile.id'] === id);
  38. };
  39. return {profileExists};
  40. }