useInteractionsCategorizedSamplesQuery.tsx 1.6 KB

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