Skip to content

Commit f8c30f1

Browse files
authored
ref(replay): Iterate on selectedReplayIndex (#94313)
Followup from comments in #94228 (comment) Depends on #94231
1 parent 045414e commit f8c30f1

File tree

6 files changed

+60
-64
lines changed

6 files changed

+60
-64
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {createContext, useCallback, useContext} from 'react';
2+
3+
import {decodeInteger} from 'sentry/utils/queryString';
4+
import useLocationQuery from 'sentry/utils/url/useLocationQuery';
5+
import {useLocation} from 'sentry/utils/useLocation';
6+
import {useNavigate} from 'sentry/utils/useNavigate';
7+
8+
const SelectedReplayIndexContext = createContext<number>(0);
9+
10+
export function SelectedReplayIndexProvider({children}: {children: React.ReactNode}) {
11+
const {selected_replay_index: selectedReplayIndex} = useLocationQuery({
12+
fields: {
13+
selected_replay_index: decodeInteger,
14+
},
15+
});
16+
17+
return (
18+
<SelectedReplayIndexContext.Provider value={selectedReplayIndex ?? 0}>
19+
{children}
20+
</SelectedReplayIndexContext.Provider>
21+
);
22+
}
23+
24+
export function useSelectedReplayIndex() {
25+
const location = useLocation();
26+
const navigate = useNavigate();
27+
28+
const index = useContext(SelectedReplayIndexContext);
29+
30+
return {
31+
index,
32+
select: useCallback(
33+
(newIndex: number) => {
34+
navigate(
35+
{
36+
pathname: location.pathname,
37+
query: {...location.query, selected_replay_index: newIndex},
38+
},
39+
{replace: true, preventScrollReset: true}
40+
);
41+
},
42+
[location, navigate]
43+
),
44+
};
45+
}

static/app/views/issueDetails/groupReplays/groupReplays.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import type {Location} from 'history';
66
import {Button} from 'sentry/components/core/button';
77
import * as Layout from 'sentry/components/layouts/thirds';
88
import Placeholder from 'sentry/components/placeholder';
9+
import {
10+
SelectedReplayIndexProvider,
11+
useSelectedReplayIndex,
12+
} from 'sentry/components/replays/queryParams/selectedReplayIndex';
913
import {Provider as ReplayContextProvider} from 'sentry/components/replays/replayContext';
1014
import {replayMobilePlatforms} from 'sentry/data/platformCategories';
1115
import {IconPlay, IconUser} from 'sentry/icons';
@@ -22,11 +26,6 @@ import {useLocation} from 'sentry/utils/useLocation';
2226
import useOrganization from 'sentry/utils/useOrganization';
2327
import {useParams} from 'sentry/utils/useParams';
2428
import GroupReplaysPlayer from 'sentry/views/issueDetails/groupReplays/groupReplaysPlayer';
25-
import {
26-
SelectedReplayIndexProvider,
27-
useSelectedReplayIndex,
28-
} from 'sentry/views/issueDetails/groupReplays/selectedReplayIndexContext';
29-
import useSelectReplayIndex from 'sentry/views/issueDetails/groupReplays/useSelectReplayIndex';
3029
import {useHasStreamlinedUI} from 'sentry/views/issueDetails/utils';
3130
import useAllMobileProj from 'sentry/views/replays/detail/useAllMobileProj';
3231
import ReplayTable from 'sentry/views/replays/replayTable';
@@ -175,8 +174,8 @@ function SelectedReplayWrapper({
175174
});
176175
const {status, replay} = readerResult;
177176

178-
const selectedReplayIndex = useSelectedReplayIndex();
179-
const {select: setSelectedReplayIndex} = useSelectReplayIndex();
177+
const {index: selectedReplayIndex, select: setSelectedReplayIndex} =
178+
useSelectedReplayIndex();
180179

181180
return (
182181
<ReplayContextProvider
@@ -216,8 +215,8 @@ function GroupReplaysTable({
216215
}) {
217216
const organization = useOrganization();
218217
const {allMobileProj} = useAllMobileProj({});
219-
const selectedReplayIndex = useSelectedReplayIndex();
220-
const {select: setSelectedReplayIndex} = useSelectReplayIndex();
218+
const {index: selectedReplayIndex, select: setSelectedReplayIndex} =
219+
useSelectedReplayIndex();
221220

222221
const {groupId} = useParams<{groupId: string}>();
223222
useCleanQueryParamsOnRouteLeave({
@@ -273,8 +272,8 @@ function ReplayOverlay({
273272
replayCount: number;
274273
replays: ReplayListRecord[];
275274
}) {
276-
const selectedReplayIndex = useSelectedReplayIndex();
277-
const {select: setSelectedReplayIndex} = useSelectReplayIndex();
275+
const {index: selectedReplayIndex, select: setSelectedReplayIndex} =
276+
useSelectedReplayIndex();
278277

279278
const nextReplay = replays?.[selectedReplayIndex + 1];
280279
const nextReplayText = nextReplay?.id

static/app/views/issueDetails/groupReplays/selectedReplayIndexContext.tsx

Lines changed: 0 additions & 24 deletions
This file was deleted.

static/app/views/issueDetails/groupReplays/useSelectReplayIndex.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

static/app/views/replays/replayTable/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styled from '@emotion/styled';
44
import {Alert} from 'sentry/components/core/alert';
55
import LoadingIndicator from 'sentry/components/loadingIndicator';
66
import {PanelTable} from 'sentry/components/panels/panelTable';
7+
import {useSelectedReplayIndex} from 'sentry/components/replays/queryParams/selectedReplayIndex';
78
import {t} from 'sentry/locale';
89
import EventView from 'sentry/utils/discover/eventView';
910
import type {Sort} from 'sentry/utils/discover/fields';
@@ -12,7 +13,6 @@ import type RequestError from 'sentry/utils/requestError/requestError';
1213
import {ERROR_MAP} from 'sentry/utils/requestError/requestError';
1314
import {useLocation} from 'sentry/utils/useLocation';
1415
import {useRoutes} from 'sentry/utils/useRoutes';
15-
import {useSelectedReplayIndex} from 'sentry/views/issueDetails/groupReplays/selectedReplayIndexContext';
1616
import type {ReplayListRecordWithTx} from 'sentry/views/performance/transactionSummary/transactionReplays/useReplaysWithTxData';
1717
import HeaderCell from 'sentry/views/replays/replayTable/headerCell';
1818
import {
@@ -76,7 +76,7 @@ function ReplayTable({
7676
const routes = useRoutes();
7777
const location = useLocation();
7878

79-
const selectedReplayIndex = useSelectedReplayIndex();
79+
const {index: selectedReplayIndex} = useSelectedReplayIndex();
8080

8181
const tableHeaders = visibleColumns
8282
.filter(Boolean)

static/app/views/replays/replayTable/tableCell.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {Tooltip} from 'sentry/components/core/tooltip';
1010
import {DropdownMenu} from 'sentry/components/dropdownMenu';
1111
import Duration from 'sentry/components/duration/duration';
1212
import Link from 'sentry/components/links/link';
13+
import {useSelectedReplayIndex} from 'sentry/components/replays/queryParams/selectedReplayIndex';
1314
import ReplayPlatformIcon from 'sentry/components/replays/replayPlatformIcon';
1415
import ReplayPlayPauseButton from 'sentry/components/replays/replayPlayPauseButton';
1516
import ScoreBar from 'sentry/components/scoreBar';
@@ -37,8 +38,6 @@ import useMedia from 'sentry/utils/useMedia';
3738
import {useNavigate} from 'sentry/utils/useNavigate';
3839
import useOrganization from 'sentry/utils/useOrganization';
3940
import useProjects from 'sentry/utils/useProjects';
40-
import {useSelectedReplayIndex} from 'sentry/views/issueDetails/groupReplays/selectedReplayIndexContext';
41-
import useSelectReplayIndex from 'sentry/views/issueDetails/groupReplays/useSelectReplayIndex';
4241
import type {ReplayListRecordWithTx} from 'sentry/views/performance/transactionSummary/transactionReplays/useReplaysWithTxData';
4342
import {makeReplaysPathname} from 'sentry/views/replays/pathnames';
4443
import type {ReplayListLocationQuery, ReplayListRecord} from 'sentry/views/replays/types';
@@ -664,8 +663,8 @@ export function ActivityCell({replay, showDropdownFilters}: Props) {
664663
}
665664

666665
export function PlayPauseCell({rowIndex}: Props) {
667-
const selectedReplayIndex = useSelectedReplayIndex();
668-
const {select: setSelectedReplayIndex} = useSelectReplayIndex();
666+
const {index: selectedReplayIndex, select: setSelectedReplayIndex} =
667+
useSelectedReplayIndex();
669668
const inner =
670669
rowIndex === selectedReplayIndex ? (
671670
<ReplayPlayPauseButton size="sm" priority="default" borderless />

0 commit comments

Comments
 (0)