Skip to content

Commit

Permalink
ref(replay): Update hydration Before/After labels to have timestamps …
Browse files Browse the repository at this point in the history
…in their tooltip (#82895)
  • Loading branch information
ryan953 authored Jan 3, 2025
1 parent 4232b60 commit 271cdb8
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 46 deletions.
5 changes: 5 additions & 0 deletions static/app/components/replays/diff/replayMutationTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {css} from '@emotion/react';
import styled from '@emotion/styled';

import DiffFeedbackBanner from 'sentry/components/replays/diff/diffFeedbackBanner';
import {After, Before, DiffHeader} from 'sentry/components/replays/diff/utils';
import StructuredEventData from 'sentry/components/structuredEventData';
import useExtractDiffMutations from 'sentry/utils/replays/hooks/useExtractDiffMutations';
import type ReplayReader from 'sentry/utils/replays/replayReader';
Expand Down Expand Up @@ -32,6 +33,10 @@ export function ReplayMutationTree({replay, leftOffsetMs, rightOffsetMs}: Props)

return (
<Fragment>
<DiffHeader>
<Before startTimestampMs={replay.getStartTimestampMs()} offset={leftOffsetMs} />
<After startTimestampMs={replay.getStartTimestampMs()} offset={rightOffsetMs} />
</DiffHeader>
{!isLoading && Object.keys(timeIndexedMutations).length === 0 ? (
<DiffFeedbackBanner />
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export function ReplaySideBySideImageDiff({leftOffsetMs, replay, rightOffsetMs}:
return (
<Flex column>
<DiffHeader>
<Before />
<After />
<Before startTimestampMs={replay.getStartTimestampMs()} offset={leftOffsetMs} />
<After startTimestampMs={replay.getStartTimestampMs()} offset={rightOffsetMs} />
</DiffHeader>

<ReplayGrid>
Expand Down
4 changes: 2 additions & 2 deletions static/app/components/replays/diff/replaySliderDiff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export function ReplaySliderDiff({
return (
<Fragment>
<DiffHeader>
<Before />
<After />
<Before startTimestampMs={replay.getStartTimestampMs()} offset={leftOffsetMs} />
<After startTimestampMs={replay.getStartTimestampMs()} offset={rightOffsetMs} />
</DiffHeader>
<WithPadding>
<Positioned style={{minHeight}} ref={positionedRef}>
Expand Down
4 changes: 2 additions & 2 deletions static/app/components/replays/diff/replayTextDiff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function ReplayTextDiff({replay, leftOffsetMs, rightOffsetMs}: Props) {
<Container>
{!isLoading && leftBody === rightBody ? <DiffFeedbackBanner /> : null}
<DiffHeader>
<Before>
<Before startTimestampMs={replay.getStartTimestampMs()} offset={leftOffsetMs}>
<CopyToClipboardButton
text={leftBody ?? ''}
size="xs"
Expand All @@ -41,7 +41,7 @@ export function ReplayTextDiff({replay, leftOffsetMs, rightOffsetMs}: Props) {
aria-label={t('Copy Before')}
/>
</Before>
<After>
<After startTimestampMs={replay.getStartTimestampMs()} offset={rightOffsetMs}>
<CopyToClipboardButton
text={rightBody ?? ''}
size="xs"
Expand Down
57 changes: 46 additions & 11 deletions static/app/components/replays/diff/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from '@emotion/styled';

import ReplayTooltipTime from 'sentry/components/replays/replayTooltipTime';
import {Tooltip} from 'sentry/components/tooltip';
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
Expand All @@ -22,28 +23,49 @@ export const DiffHeader = styled('div')`
}
`;

const Label = styled('div')`
display: flex;
align-items: center;
font-weight: bold;
`;
interface BeforeAfterProps {
offset: number;
startTimestampMs: number;
children?: React.ReactNode;
}

export function Before({children}: {children?: React.ReactNode}) {
export function Before({children, offset, startTimestampMs}: BeforeAfterProps) {
return (
<Tooltip title={t('How the initial server-rendered page looked.')}>
<Tooltip
title={
<LeftAligned>
{t('The server-rendered page')}
<div>
<ReplayTooltipTime
timestampMs={startTimestampMs + offset}
startTimestampMs={startTimestampMs}
/>
</div>
</LeftAligned>
}
>
<Label>
{t('Before')}
{children}
</Label>
</Tooltip>
);
}
export function After({children}: {children?: React.ReactNode}) {

export function After({children, offset, startTimestampMs}: BeforeAfterProps) {
return (
<Tooltip
title={t(
'How React re-rendered the page on your browser, after detecting a hydration error.'
)}
title={
<LeftAligned>
{t('After React re-rendered the page, and reported a hydration error')}
<div>
<ReplayTooltipTime
timestampMs={startTimestampMs + offset}
startTimestampMs={startTimestampMs}
/>
</div>
</LeftAligned>
}
>
<Label>
{t('After')}
Expand All @@ -52,3 +74,16 @@ export function After({children}: {children?: React.ReactNode}) {
</Tooltip>
);
}

const LeftAligned = styled('div')`
text-align: left;
display: flex;
gap: ${space(1)};
flex-direction: column;
`;

const Label = styled('div')`
display: flex;
align-items: center;
font-weight: bold;
`;
44 changes: 44 additions & 0 deletions static/app/components/replays/replayTooltipTime.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {Fragment} from 'react';
import styled from '@emotion/styled';

import {t} from 'sentry/locale';
import {getFormat, getFormattedDate} from 'sentry/utils/dates';
import formatDuration from 'sentry/utils/duration/formatDuration';

interface Props {
startTimestampMs: number;
timestampMs: number;
}

export default function ReplayTooltipTime({startTimestampMs, timestampMs}: Props) {
return (
<Fragment>
<TooltipTime>
{t(
'Date: %s',
getFormattedDate(
timestampMs,
`${getFormat({year: true, seconds: true, timeZone: true})}`,
{
local: true,
}
)
)}
</TooltipTime>
<TooltipTime>
{t(
'Time within replay: %s',
formatDuration({
duration: [Math.abs(timestampMs - startTimestampMs), 'ms'],
precision: 'ms',
style: 'hh:mm:ss.sss',
})
)}
</TooltipTime>
</Fragment>
);
}

const TooltipTime = styled('div')`
text-align: left;
`;
34 changes: 5 additions & 29 deletions static/app/views/replays/detail/timestampButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import styled from '@emotion/styled';

import {DateTime} from 'sentry/components/dateTime';
import Duration from 'sentry/components/duration/duration';
import ReplayTooltipTime from 'sentry/components/replays/replayTooltipTime';
import {Tooltip} from 'sentry/components/tooltip';
import {IconPlay} from 'sentry/icons';
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import {getFormat, getFormattedDate} from 'sentry/utils/dates';
import formatDuration from 'sentry/utils/duration/formatDuration';
import {useReplayPrefs} from 'sentry/utils/replays/playback/providers/replayPreferencesContext';

type Props = {
Expand All @@ -32,28 +30,10 @@ export default function TimestampButton({
<Tooltip
title={
<div>
<TooltipTime>
{t(
'Date: %s',
getFormattedDate(
timestampMs,
`${getFormat({year: true, seconds: true, timeZone: true})}`,
{
local: true,
}
)
)}
</TooltipTime>
<TooltipTime>
{t(
'Time within replay: %s',
formatDuration({
duration: [Math.abs(timestampMs - startTimestampMs), 'ms'],
precision: 'ms',
style: 'hh:mm:ss.sss',
})
)}
</TooltipTime>
<ReplayTooltipTime
timestampMs={timestampMs}
startTimestampMs={startTimestampMs}
/>
</div>
}
skipWrapper
Expand All @@ -77,10 +57,6 @@ export default function TimestampButton({
);
}

const TooltipTime = styled('div')`
text-align: left;
`;

const StyledButton = styled('button')`
background: transparent;
border: none;
Expand Down

0 comments on commit 271cdb8

Please sign in to comment.