useTransactionWebVitalsQuery.tsx 1.4 KB

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