useInteractionElementQuery.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 all interactionElements on the selected project(s)
  12. */
  13. export const useInteractionElementQuery = () => {
  14. const location = useLocation();
  15. const pageFilters = usePageFilters();
  16. const {slug: orgSlug} = useOrganization();
  17. const browserFilters = useBrowserModuleFilters();
  18. const fields = ['interactionElement', 'count()'];
  19. const queryConditions = [
  20. 'has:interactionElement',
  21. browserFilters.page ? `transaction:"${browserFilters.page}"` : '',
  22. browserFilters['transaction.op']
  23. ? `transaction.op:"${browserFilters[BrowserStarfishFields.TRANSACTION_OP]}"`
  24. : '',
  25. ];
  26. const eventView = EventView.fromNewQueryWithPageFilters(
  27. {
  28. fields,
  29. name: 'Interaction module - page selector',
  30. version: 2,
  31. query: queryConditions.join(' '),
  32. orderby: 'interactionElement',
  33. },
  34. pageFilters.selection
  35. );
  36. const result = useDiscoverQuery({
  37. eventView,
  38. location,
  39. orgSlug,
  40. limit: 100,
  41. });
  42. const interactionElements =
  43. result?.data?.data.map(row => row.interactionElement.toString()) || [];
  44. return {...result, data: interactionElements};
  45. };