useInteractionQuery.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 {useBrowserModuleFilters} from 'sentry/views/performance/browser/useBrowserFilters';
  7. export const useInteractionQuery = () => {
  8. const pageFilters = usePageFilters();
  9. const browserFilters = useBrowserModuleFilters();
  10. const location = useLocation();
  11. const {slug: orgSlug} = useOrganization();
  12. const queryConditions = [
  13. `transaction:"${browserFilters.page}"`,
  14. `interactionElement:"${browserFilters.component?.replaceAll('"', '\\"')}"`,
  15. ];
  16. // TODO - we should be using metrics data here
  17. const eventView = EventView.fromNewQueryWithPageFilters(
  18. {
  19. fields: ['id', 'transaction.duration', 'project'],
  20. name: 'Interaction module - interactions table',
  21. query: queryConditions.join(' '),
  22. orderby: '-transaction.duration',
  23. version: 2,
  24. },
  25. pageFilters.selection
  26. );
  27. const result = useDiscoverQuery({eventView, limit: 15, location, orgSlug});
  28. const data = result?.data?.data.map(row => ({
  29. eventId: row.id.toString(),
  30. project: row.project.toString(),
  31. 'transaction.duration': row['transaction.duration'] as number,
  32. }));
  33. return {...result, data: data || []};
  34. };