Skip to content

Commit f70bbdf

Browse files
jerryzhou196Jesse-Box
authored andcommitted
fix(replay): fix useReplayList hook (#103063)
#79136 fixed a bug, but the hardcoding should be specific to `transactionReplays`, rather than the `fetchReplayList` hook.
1 parent c6de78d commit f70bbdf

File tree

6 files changed

+30
-36
lines changed

6 files changed

+30
-36
lines changed

static/app/utils/replays/fetchReplayList.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,7 @@ async function fetchReplayList({
7676
return {
7777
fetchError: undefined,
7878
pageLinks,
79-
replays: payload.query ? data.map(mapResponseToReplayRecord) : [],
80-
// for the replay tab in transactions, if payload.query is undefined,
81-
// this means the transaction has no related replays.
82-
// but because we cannot query for an empty list of IDs (e.g. `id:[]` breaks our search endpoint),
83-
// and leaving query empty results in ALL replays being returned for a specified project
84-
// (which doesn't make sense as we want to show no replays),
85-
// we essentially want to hardcode no replays being returned.
79+
replays: data.map(mapResponseToReplayRecord),
8680
};
8781
} catch (error: any) {
8882
if (error.responseJSON?.detail) {

static/app/utils/replays/hooks/useReplayList.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
} from 'sentry/views/replays/types';
1313

1414
type Options = {
15+
enabled: boolean;
1516
eventView: EventView;
1617
location: Location<ReplayListLocationQuery>;
1718
organization: Organization;
@@ -24,6 +25,7 @@ type State = Awaited<ReturnType<typeof fetchReplayList>> & {isFetching: boolean}
2425
type Result = State;
2526

2627
function useReplayList({
28+
enabled = true,
2729
eventView,
2830
location,
2931
organization,
@@ -46,6 +48,13 @@ function useReplayList({
4648
...prev,
4749
isFetching: true,
4850
}));
51+
if (!enabled) {
52+
setData(prev => ({
53+
...prev,
54+
isFetching: false,
55+
}));
56+
return;
57+
}
4958
const response = await fetchReplayList({
5059
api,
5160
organization,
@@ -57,7 +66,16 @@ function useReplayList({
5766
});
5867

5968
setData({...response, isFetching: false});
60-
}, [api, organization, location, eventView, queryReferrer, perPage, selection]);
69+
}, [
70+
api,
71+
organization,
72+
location,
73+
eventView,
74+
queryReferrer,
75+
perPage,
76+
selection,
77+
enabled,
78+
]);
6179

6280
useEffect(() => {
6381
loadReplays();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ function GroupReplaysTable({
234234
});
235235

236236
const replayListData = useReplayList({
237+
enabled: true,
237238
eventView,
238239
location: useMemo(() => ({query: {}}) as Location<ReplayListLocationQuery>, []),
239240
organization,

static/app/views/performance/transactionSummary/transactionReplays/index.spec.tsx

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ const renderComponent = ({
7272

7373
describe('TransactionReplays', () => {
7474
let eventsMockApi: jest.Mock<any, any>;
75-
let replaysMockApi: jest.Mock<any, any>;
7675
beforeEach(() => {
7776
MockApiClient.addMockResponse({
7877
method: 'GET',
@@ -97,13 +96,6 @@ describe('TransactionReplays', () => {
9796
},
9897
statusCode: 200,
9998
});
100-
replaysMockApi = MockApiClient.addMockResponse({
101-
url: '/organizations/org-slug/replays/',
102-
body: {
103-
data: [],
104-
},
105-
statusCode: 200,
106-
});
10799
});
108100

109101
afterEach(() => {
@@ -140,29 +132,10 @@ describe('TransactionReplays', () => {
140132
});
141133
});
142134

143-
it('should snapshot empty state', async () => {
144-
const mockApi = MockApiClient.addMockResponse({
145-
url: mockReplaysUrl,
146-
body: {
147-
data: [],
148-
},
149-
statusCode: 200,
150-
});
151-
152-
renderComponent();
153-
154-
await waitFor(() => {
155-
expect(mockApi).toHaveBeenCalledTimes(1);
156-
});
157-
});
158-
159135
it('should show empty message when no replays are found', async () => {
160136
renderComponent();
161137

162-
await waitFor(() => {
163-
expect(replaysMockApi).toHaveBeenCalledTimes(1);
164-
});
165-
expect(screen.getByText('No replays found')).toBeInTheDocument();
138+
await screen.findByText('No replays found');
166139
});
167140

168141
it('should show loading indicator when loading replays', async () => {

static/app/views/performance/transactionSummary/transactionReplays/transactionReplays.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ function ReplaysContent({
9898
const hasRoomForColumns = useMedia(`(min-width: ${theme.breakpoints.sm})`);
9999

100100
const {replays, isFetching, fetchError} = useReplayList({
101+
enabled: eventView.query !== '',
102+
// for the replay tab in transactions, if payload.query is undefined,
103+
// this means the transaction has no related replays.
104+
// but because we cannot query for an empty list of IDs (e.g. `id:[]` breaks our search endpoint),
105+
// and leaving query empty results in ALL replays being returned for a specified project
106+
// (which doesn't make sense as we want to show no replays),
107+
// we essentially want to hardcode no replays being returned.
101108
eventView,
102109
location: newLocation,
103110
organization,

static/app/views/replays/selectors/exampleReplaysList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default function ExampleReplaysList({
7474
);
7575

7676
const {replays, isFetching, fetchError} = useReplayList({
77+
enabled: true,
7778
eventView,
7879
location: emptyLocation,
7980
organization,

0 commit comments

Comments
 (0)