useInteractionsCategorizedSamplesQuery.tsx 1.9 KB

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