measurements.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {Fragment} from 'react';
  2. import {
  3. MOBILE_VITAL_DETAILS,
  4. WEB_VITAL_DETAILS,
  5. } from 'sentry/utils/performance/vitals/constants';
  6. import {Vital} from 'sentry/utils/performance/vitals/types';
  7. import {MobileVital, WebVital} from '../fields';
  8. export type Measurement = {
  9. key: string;
  10. name: string;
  11. };
  12. export type MeasurementCollection = Record<string, Measurement>;
  13. type VitalType = WebVital | MobileVital;
  14. function measurementsFromDetails(
  15. details: Partial<Record<VitalType, Vital>>
  16. ): MeasurementCollection {
  17. return Object.fromEntries(
  18. Object.entries(details).map(([key, value]) => {
  19. const newValue: Measurement = {
  20. name: value.name,
  21. key,
  22. };
  23. return [key, newValue];
  24. })
  25. );
  26. }
  27. const MOBILE_MEASUREMENTS = measurementsFromDetails(MOBILE_VITAL_DETAILS);
  28. const WEB_MEASUREMENTS = measurementsFromDetails(WEB_VITAL_DETAILS);
  29. export function getMeasurements() {
  30. return {...WEB_MEASUREMENTS, ...MOBILE_MEASUREMENTS};
  31. }
  32. type ChildrenProps = {
  33. measurements: MeasurementCollection;
  34. };
  35. type Props = {
  36. children: (props: ChildrenProps) => React.ReactNode;
  37. };
  38. function Measurements({children}: Props) {
  39. const measurements = getMeasurements();
  40. return <Fragment>{children({measurements})}</Fragment>;
  41. }
  42. export default Measurements;