useTransactionWebVitalsQuery.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. limit,
  15. transaction,
  16. defaultSort,
  17. sortName = 'sort',
  18. }: Props) => {
  19. const storedScoresResult = useTransactionWebVitalsScoresQuery({
  20. limit,
  21. transaction,
  22. defaultSort,
  23. sortName,
  24. enabled: USE_STORED_SCORES,
  25. });
  26. const rawWebVitalsResult = useTransactionRawWebVitalsQuery({
  27. limit,
  28. transaction,
  29. defaultSort,
  30. sortName,
  31. enabled: !USE_STORED_SCORES,
  32. });
  33. if (USE_STORED_SCORES) {
  34. return storedScoresResult;
  35. }
  36. return rawWebVitalsResult;
  37. };