useTransactions.tsx 994 B

1234567891011121314151617181920212223242526272829303132333435
  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. type Transaction = {
  6. id: string;
  7. 'project.name': string;
  8. timestamp: string;
  9. 'transaction.duration': number;
  10. };
  11. export function useTransactions(eventIDs: string[], referrer = 'use-transactions') {
  12. const location = useLocation();
  13. const {slug} = useOrganization();
  14. const eventView = EventView.fromNewQueryWithLocation(
  15. {
  16. fields: ['id', 'timestamp', 'project.name', 'transaction.duration'],
  17. name: 'Transactions',
  18. projects: [1],
  19. version: 2,
  20. query: `id:[${eventIDs.join(',')}]`,
  21. },
  22. location
  23. );
  24. const response = useDiscoverQuery({eventView, location, orgSlug: slug, referrer});
  25. const data = (response.data?.data ?? []) as unknown as Transaction[];
  26. return {
  27. ...response,
  28. data,
  29. };
  30. }