useTransactionWebVitalsQuery.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {Sort} from 'sentry/utils/discover/fields';
  2. import {USE_STORED_SCORES} from 'sentry/views/performance/browser/webVitals/settings';
  3. import {useTransactionRawWebVitalsQuery} from 'sentry/views/performance/browser/webVitals/utils/queries/rawWebVitalsQueries/useTransactionRawWebVitalsQuery';
  4. import {useTransactionWebVitalsScoresQuery} from 'sentry/views/performance/browser/webVitals/utils/queries/storedScoreQueries/useTransactionWebVitalsScoresQuery';
  5. import {WebVitals} from 'sentry/views/performance/browser/webVitals/utils/types';
  6. type Props = {
  7. defaultSort?: Sort;
  8. limit?: number;
  9. orderBy?: WebVitals | null;
  10. sortName?: string;
  11. transaction?: string | null;
  12. };
  13. export const useTransactionWebVitalsQuery = ({
  14. orderBy,
  15. limit,
  16. transaction,
  17. defaultSort,
  18. sortName = 'sort',
  19. }: Props) => {
  20. const storedScoresResult = useTransactionWebVitalsScoresQuery({
  21. orderBy,
  22. limit,
  23. transaction,
  24. defaultSort,
  25. sortName,
  26. enabled: USE_STORED_SCORES,
  27. });
  28. const rawWebVitalsResult = useTransactionRawWebVitalsQuery({
  29. orderBy,
  30. limit,
  31. transaction,
  32. defaultSort,
  33. sortName,
  34. enabled: !USE_STORED_SCORES,
  35. });
  36. if (USE_STORED_SCORES) {
  37. return storedScoresResult;
  38. }
  39. return rawWebVitalsResult;
  40. };