useTransactionSamplesWebVitalsQuery.tsx 1.5 KB

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