useInteractionsCategorizedSamplesQuery.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {useInpSpanSamplesWebVitalsQuery} from 'sentry/views/insights/browser/webVitals/queries/useInpSpanSamplesWebVitalsQuery';
  2. import type {InteractionSpanSampleRowWithScore} from 'sentry/views/insights/browser/webVitals/types';
  3. import type {BrowserType} from 'sentry/views/insights/browser/webVitals/utils/queryParameterDecoders/browserType';
  4. import {
  5. PERFORMANCE_SCORE_MEDIANS,
  6. PERFORMANCE_SCORE_P90S,
  7. } from 'sentry/views/insights/browser/webVitals/utils/scoreThresholds';
  8. type Props = {
  9. browserTypes: BrowserType[];
  10. enabled: boolean;
  11. transaction: string;
  12. };
  13. export function useInteractionsCategorizedSamplesQuery({
  14. transaction,
  15. enabled,
  16. browserTypes,
  17. }: Props) {
  18. const {data: goodData, isFetching: isGoodDataLoading} = useInpSpanSamplesWebVitalsQuery(
  19. {
  20. transaction,
  21. enabled,
  22. limit: 3,
  23. filters: {
  24. 'measurements.inp': `<${PERFORMANCE_SCORE_P90S.inp}`,
  25. },
  26. browserTypes,
  27. }
  28. );
  29. const {data: mehData, isFetching: isMehDataLoading} = useInpSpanSamplesWebVitalsQuery({
  30. transaction,
  31. enabled,
  32. limit: 3,
  33. filters: {
  34. 'measurements.inp': [
  35. `>=${PERFORMANCE_SCORE_P90S.inp}`,
  36. `<${PERFORMANCE_SCORE_MEDIANS.inp}`,
  37. ],
  38. },
  39. browserTypes,
  40. });
  41. const {data: poorData, isFetching: isBadDataLoading} = useInpSpanSamplesWebVitalsQuery({
  42. transaction,
  43. enabled,
  44. limit: 3,
  45. filters: {
  46. 'measurements.inp': `>=${PERFORMANCE_SCORE_MEDIANS.inp}`,
  47. },
  48. browserTypes,
  49. });
  50. const data = [...goodData, ...mehData, ...poorData];
  51. const isLoading = isGoodDataLoading || isMehDataLoading || isBadDataLoading;
  52. const interactionsTableData: InteractionSpanSampleRowWithScore[] = data.sort(
  53. (a, b) => a.inpScore - b.inpScore
  54. );
  55. return {
  56. data: interactionsTableData,
  57. isLoading,
  58. };
  59. }