Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
c298lee committed Sep 12, 2024
1 parent 57e2d4c commit 307d57c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
7 changes: 2 additions & 5 deletions static/app/components/replays/breadcrumbs/breadcrumbItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
} from 'sentry/utils/replays/types';
import {
isBreadcrumbFrame,
isCLSFrame,
isErrorFrame,
isFeedbackFrame,
isHydrationErrorFrame,
Expand Down Expand Up @@ -237,11 +238,7 @@ function WebVitalData({
const selectors = frameToExtraction?.get(frame)?.selectors;

const webVitalData = {value: frame.data.value};
if (
frame.description === 'cumulative-layout-shift' &&
frame.data.attributions &&
selectors
) {
if (isCLSFrame(frame) && frame.data.attributions && selectors) {
const layoutShifts: {[x: string]: ReactNode[]}[] = [];
for (const attr of frame.data.attributions) {
const elements: ReactNode[] = [];
Expand Down
13 changes: 7 additions & 6 deletions static/app/utils/replays/getFrameDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import type {
} from 'sentry/utils/replays/types';
import {
getFrameOpOrCategory,
isCLSFrame,
isDeadClick,
isDeadRageClick,
isRageClick,
Expand Down Expand Up @@ -286,9 +287,9 @@ const MAPPER_FOR_FRAME: Record<string, (frame) => Details> = {
case 'good':
return {
color: 'green300',
description: tct('[value][ms] (Good)', {
description: tct('[value][unit] (Good)', {
value: frame.data.value.toFixed(2),
ms: frame.description === 'cumulative-layout-shift' ? '' : 'ms',
unit: isCLSFrame(frame) ? '' : 'ms',
}),
tabKey: TabKey.NETWORK,
title: 'Web Vital: ' + toTitleCase(explodeSlug(frame.description)),
Expand All @@ -297,9 +298,9 @@ const MAPPER_FOR_FRAME: Record<string, (frame) => Details> = {
case 'needs-improvement':
return {
color: 'yellow300',
description: tct('[value][ms] (Meh)', {
description: tct('[value][unit] (Meh)', {
value: frame.data.value.toFixed(2),
ms: frame.description === 'cumulative-layout-shift' ? '' : 'ms',
unit: isCLSFrame(frame) ? '' : 'ms',
}),
tabKey: TabKey.NETWORK,
title: 'Web Vital: ' + toTitleCase(explodeSlug(frame.description)),
Expand All @@ -308,9 +309,9 @@ const MAPPER_FOR_FRAME: Record<string, (frame) => Details> = {
default:
return {
color: 'red300',
description: tct('[value][ms] (Poor)', {
description: tct('[value][unit] (Poor)', {
value: frame.data.value.toFixed(2),
ms: frame.description === 'cumulative-layout-shift' ? '' : 'ms',
unit: isCLSFrame(frame) ? '' : 'ms',
}),
tabKey: TabKey.NETWORK,
title: 'Web Vital: ' + toTitleCase(explodeSlug(frame.description)),
Expand Down
11 changes: 6 additions & 5 deletions static/app/utils/replays/replayReader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
EventType,
getNodeIds,
IncrementalSource,
isCLSFrame,
isDeadClick,
isDeadRageClick,
isPaintFrame,
Expand Down Expand Up @@ -637,12 +638,12 @@ export default class ReplayReader {
let lastTimestamp = 0;
const groupedCls: WebVitalFrame[] = [];

for (const cls of allWebVitals) {
if (cls.description === 'cumulative-layout-shift') {
if (lastTimestamp === cls.timestampMs) {
groupedCls.push(cls);
for (const frame of allWebVitals) {
if (isCLSFrame(frame)) {
if (lastTimestamp === frame.timestampMs) {
groupedCls.push(frame);
} else {
lastTimestamp = cls.timestampMs;
lastTimestamp = frame.timestampMs;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions static/app/utils/replays/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ export function isWebVitalFrame(frame: SpanFrame): frame is WebVitalFrame {
return frame.op === 'web-vital';
}

export function isCLSFrame(frame: WebVitalFrame): frame is WebVitalFrame {
return frame.description === 'cumulative-layout-shift';
}

export function isPaintFrame(frame: SpanFrame): frame is PaintFrame {
return frame.op === 'paint';
}
Expand Down

0 comments on commit 307d57c

Please sign in to comment.