usePageQuery.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {useDiscoverQuery} from 'sentry/utils/discover/discoverQuery';
  2. import EventView from 'sentry/utils/discover/eventView';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import useOrganization from 'sentry/utils/useOrganization';
  5. import usePageFilters from 'sentry/utils/usePageFilters';
  6. import {
  7. BrowserStarfishFields,
  8. useBrowserModuleFilters,
  9. } from 'sentry/views/performance/browser/useBrowserFilters';
  10. /**
  11. * Gets a list of pages on the selected project(s)
  12. */
  13. export const usePagesQuery = () => {
  14. const location = useLocation();
  15. const pageFilters = usePageFilters();
  16. const {slug: orgSlug} = useOrganization();
  17. const browserFilters = useBrowserModuleFilters();
  18. const fields = ['transaction', 'p75(transaction.duration)', 'tpm()'];
  19. const queryConditions = [
  20. 'event.type:transaction',
  21. browserFilters.component ? `interactionElement:"${browserFilters.component}"` : '',
  22. browserFilters['transaction.op']
  23. ? `transaction.op:"${browserFilters[BrowserStarfishFields.TRANSACTION_OP]}"`
  24. : '',
  25. ]; // TODO: We will need to consider other ops
  26. const eventView = EventView.fromNewQueryWithPageFilters(
  27. {
  28. fields, // for some reason we need a function, otherwise the query fails
  29. name: 'Interaction module - page selector',
  30. version: 2,
  31. query: queryConditions.join(' '),
  32. orderby: 'transaction',
  33. },
  34. pageFilters.selection
  35. );
  36. const result = useDiscoverQuery({
  37. eventView,
  38. location,
  39. orgSlug,
  40. limit: 100,
  41. });
  42. const pages = result?.data?.data.map(row => row.transaction.toString()) || [];
  43. return {...result, data: pages};
  44. };