12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import {
- PERFORMANCE_SCORE_MEDIANS,
- PERFORMANCE_SCORE_P90S,
- } from 'sentry/views/performance/browser/webVitals/utils/queries/rawWebVitalsQueries/calculatePerformanceScore';
- import {useTransactionSamplesWebVitalsQuery} from 'sentry/views/performance/browser/webVitals/utils/queries/useTransactionSamplesWebVitalsQuery';
- import type {
- TransactionSampleRowWithScore,
- WebVitals,
- } from 'sentry/views/performance/browser/webVitals/utils/types';
- type Props = {
- enabled: boolean;
- transaction: string;
- webVital: WebVitals | null;
- };
- export function useGoodMehAndBadTransactionsSamplesQuery({
- transaction,
- webVital,
- enabled,
- }: Props) {
- const {data: goodData, isLoading: isGoodTransactionWebVitalsQueryLoading} =
- useTransactionSamplesWebVitalsQuery({
- limit: 3,
- transaction: transaction ?? '',
- query: webVital
- ? `measurements.${webVital}:<${PERFORMANCE_SCORE_P90S[webVital]}`
- : undefined,
- enabled,
- withProfiles: true,
- sortName: 'webVitalSort',
- webVital: webVital ?? undefined,
- });
- const {data: mehData, isLoading: isMehTransactionWebVitalsQueryLoading} =
- useTransactionSamplesWebVitalsQuery({
- limit: 3,
- transaction: transaction ?? '',
- query: webVital
- ? `measurements.${webVital}:<${PERFORMANCE_SCORE_MEDIANS[webVital]} measurements.${webVital}:>=${PERFORMANCE_SCORE_P90S[webVital]}`
- : undefined,
- enabled,
- withProfiles: true,
- sortName: 'webVitalSort',
- webVital: webVital ?? undefined,
- });
- const {data: poorData, isLoading: isPoorTransactionWebVitalsQueryLoading} =
- useTransactionSamplesWebVitalsQuery({
- limit: 3,
- transaction: transaction ?? '',
- query: webVital
- ? `measurements.${webVital}:>=${PERFORMANCE_SCORE_MEDIANS[webVital]}`
- : undefined,
- enabled,
- withProfiles: true,
- sortName: 'webVitalSort',
- webVital: webVital ?? undefined,
- });
- const data = [...goodData, ...mehData, ...poorData];
- const isTransactionWebVitalsQueryLoading =
- isGoodTransactionWebVitalsQueryLoading ||
- isMehTransactionWebVitalsQueryLoading ||
- isPoorTransactionWebVitalsQueryLoading;
- const transactionsTableData: TransactionSampleRowWithScore[] = data.sort(
- (a, b) => a[`${webVital}Score`] - b[`${webVital}Score`]
- );
- return {
- data: transactionsTableData,
- isLoading: isTransactionWebVitalsQueryLoading,
- };
- }
|