Skip to content

feat(replay): add time duration for each playback speed #94888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 8, 2025
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import styled from '@emotion/styled';

import {Button} from 'sentry/components/core/button';
import {CompositeSelect} from 'sentry/components/core/compactSelect/composite';
import {Flex} from 'sentry/components/core/layout';
import {useReplayContext} from 'sentry/components/replays/replayContext';
import {IconSettings} from 'sentry/icons';
import {t} from 'sentry/locale';
import formatDuration from 'sentry/utils/duration/formatDuration';
import {useReplayPrefs} from 'sentry/utils/replays/playback/providers/replayPreferencesContext';
import {toTitleCase} from 'sentry/utils/string/toTitleCase';

Expand All @@ -17,9 +22,24 @@ export default function ReplayPreferenceDropdown({
isLoading?: boolean;
}) {
const [prefs, setPrefs] = useReplayPrefs();
const {isFetching, replay} = useReplayContext();

const SKIP_OPTION_VALUE = 'skip';

// Calculate adjusted duration for each speed, rounded up to the nearest second.
// Returns in seconds
const calculateAdjustedDuration = (originalDurationMs: number, speed: number) => {
if (speed === 1) {
return originalDurationMs / 1000;
}

return Math.ceil(originalDurationMs / speed / 1000);
};

// Check if we should show duration (data is loaded and duration is available)
const shouldShowDuration =
!isLoading && !isFetching && replay && replay.getDurationMs() > 0;

return (
<CompositeSelect
disabled={isLoading}
Expand All @@ -37,10 +57,35 @@ export default function ReplayPreferenceDropdown({
label={t('Playback Speed')}
value={prefs.playbackSpeed}
onChange={opt => setPrefs({playbackSpeed: opt.value})}
options={speedOptions.map(option => ({
label: `${option}x`,
value: option,
}))}
options={speedOptions.map(option => {
const baseLabel = `${option}x`;

if (shouldShowDuration) {
const adjustedDurationMs = calculateAdjustedDuration(
replay.getDurationMs(),
option
);
const durationDisplay = formatDuration({
duration: [adjustedDurationMs, 'sec'],
precision: 'sec',
style: 'h:mm:ss',
});
return {
label: (
<Flex justify="space-between">
<span>{baseLabel}</span>
<DurationDisplay>{durationDisplay}</DurationDisplay>
</Flex>
),
value: option,
};
}

return {
label: baseLabel,
value: option,
};
})}
/>
<CompositeSelect.Region
label={t('Timestamps')}
Expand Down Expand Up @@ -68,3 +113,7 @@ export default function ReplayPreferenceDropdown({
</CompositeSelect>
);
}

const DurationDisplay = styled('span')`
color: ${p => p.theme.subText};
`;
Loading