mapWebVitalToOrderBy.tsx 688 B

123456789101112131415161718192021222324
  1. import {getAggregateAlias} from 'sentry/utils/discover/fields';
  2. import type {WebVitals} from 'sentry/views/performance/browser/webVitals/utils/types';
  3. export const mapWebVitalToOrderBy = (
  4. webVital?: WebVitals | null,
  5. aggregateFunction?: 'avg' | 'p75'
  6. ) => {
  7. let webVitalKey = webVital ? WEBVITAL_TO_KEY[webVital] : undefined;
  8. if (!webVitalKey) {
  9. return undefined;
  10. }
  11. if (aggregateFunction) {
  12. webVitalKey = getAggregateAlias(`${aggregateFunction}(${webVitalKey})`);
  13. }
  14. return `-${webVitalKey}`;
  15. };
  16. const WEBVITAL_TO_KEY = {
  17. lcp: 'measurements.lcp',
  18. fcp: 'measurements.fcp',
  19. cls: 'measurements.cls',
  20. ttfb: 'measurements.ttfb',
  21. fid: 'measurements.fid',
  22. };