useInteractionsQuery.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. import type {ValidSort} from 'sentry/views/performance/browser/useBrowserSort';
  11. export const useInteractionsQuery = ({sort}: {sort: ValidSort}) => {
  12. const pageFilters = usePageFilters();
  13. const browserFilters = useBrowserModuleFilters();
  14. const location = useLocation();
  15. const {slug: orgSlug} = useOrganization();
  16. const queryConditions = [
  17. 'has:interactionElement',
  18. browserFilters.page ? `transaction:"${browserFilters.page}"` : '',
  19. browserFilters.component ? `interactionElement:"${browserFilters.component}"` : '',
  20. browserFilters['transaction.op']
  21. ? `transaction.op:"${browserFilters[BrowserStarfishFields.TRANSACTION_OP]}"`
  22. : '',
  23. ];
  24. // TODO - we should be using metrics data here
  25. const eventView = EventView.fromNewQueryWithPageFilters(
  26. {
  27. fields: [
  28. 'interactionElement',
  29. 'transaction',
  30. 'transaction.op',
  31. 'p75(transaction.duration)',
  32. 'count()',
  33. ],
  34. name: 'Interaction module - interactions table',
  35. query: queryConditions.join(' '),
  36. orderby: '-count',
  37. version: 2,
  38. },
  39. pageFilters.selection
  40. );
  41. if (sort) {
  42. eventView.sorts = [sort];
  43. }
  44. const result = useDiscoverQuery({eventView, limit: 50, location, orgSlug});
  45. const data = result?.data?.data.map(row => ({
  46. transaction: row.transaction.toString(),
  47. interactionElement: row.interactionElement.toString(),
  48. 'transaction.op': row['transaction.op'].toString(),
  49. 'p75(transaction.duration)': row['p75(transaction.duration)'] as number,
  50. 'count()': row['count()'] as number,
  51. }));
  52. return {...result, data: data || []};
  53. };