getWebVitalValues.tsx 1.2 KB

123456789101112131415161718192021222324252627282930
  1. import type {TableDataRow} from 'sentry/utils/discover/discoverQuery';
  2. import type {Vitals} from 'sentry/views/performance/browser/webVitals/utils/queries/rawWebVitalsQueries/calculatePerformanceScore';
  3. import type {WebVitals} from 'sentry/views/performance/browser/webVitals/utils/types';
  4. function hasWebVital(data: TableDataRow, webVital: WebVitals): boolean {
  5. if (data.hasOwnProperty(`count_web_vitals(measurements.${webVital}, any)`)) {
  6. return (data[`count_web_vitals(measurements.${webVital}, any)`] as number) > 0;
  7. }
  8. return false;
  9. }
  10. function getWebVital(data: TableDataRow, webVital: WebVitals): number {
  11. return data[`p75(measurements.${webVital})`] as number;
  12. }
  13. export function getWebVitalsFromTableData(data: TableDataRow): Vitals {
  14. const hasLcp = hasWebVital(data, 'lcp');
  15. const hasFcp = hasWebVital(data, 'fcp');
  16. const hasCls = hasWebVital(data, 'cls');
  17. const hasFid = hasWebVital(data, 'fid');
  18. const hasTtfb = hasWebVital(data, 'ttfb');
  19. return {
  20. lcp: hasLcp ? getWebVital(data, 'lcp') : undefined,
  21. fcp: hasFcp ? getWebVital(data, 'fcp') : undefined,
  22. cls: hasCls ? getWebVital(data, 'cls') : undefined,
  23. ttfb: hasTtfb ? getWebVital(data, 'ttfb') : undefined,
  24. fid: hasFid ? getWebVital(data, 'fid') : undefined,
  25. };
  26. }