mapWebVitalToOrderBy.tsx 788 B

123456789101112131415161718192021222324
  1. import {getAggregateAlias} from 'sentry/utils/discover/fields';
  2. import type {WebVitals} from 'sentry/views/insights/browser/webVitals/types';
  3. export const mapWebVitalToOrderBy = (
  4. webVital?: WebVitals | null,
  5. aggregateFunction?: 'avg' | 'p75'
  6. ) => {
  7. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  8. let webVitalKey = webVital ? WEBVITAL_TO_KEY[webVital] : undefined;
  9. if (!webVitalKey) {
  10. return undefined;
  11. }
  12. if (aggregateFunction) {
  13. webVitalKey = getAggregateAlias(`${aggregateFunction}(${webVitalKey})`);
  14. }
  15. return `-${webVitalKey}`;
  16. };
  17. const WEBVITAL_TO_KEY = {
  18. lcp: 'measurements.lcp',
  19. fcp: 'measurements.fcp',
  20. cls: 'measurements.cls',
  21. ttfb: 'measurements.ttfb',
  22. };