Skip to content

Commit 67b950a

Browse files
authored
chore: Update usePullPageData to TSQ V5 (#3536)
1 parent b2a584b commit 67b950a

16 files changed

+340
-209
lines changed

src/pages/PullRequestPage/PullBundleAnalysis/PullBundleAnalysis.test.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
2+
import {
3+
QueryClientProvider as QueryClientProviderV5,
4+
QueryClient as QueryClientV5,
5+
} from '@tanstack/react-queryV5'
26
import {
37
render,
48
screen,
@@ -11,7 +15,7 @@ import { MemoryRouter, Route } from 'react-router-dom'
1115

1216
import PullBundleAnalysis from './PullBundleAnalysis'
1317

14-
import { TBundleAnalysisComparisonResult } from '../hooks'
18+
import { TBundleAnalysisComparisonResult } from '../queries/PullPageDataQueryOpts'
1519

1620
vi.mock('./EmptyTable', () => ({
1721
default: () => <div>EmptyTable</div>,
@@ -106,24 +110,30 @@ const mockRepoOverview = ({
106110
const queryClient = new QueryClient({
107111
defaultOptions: { queries: { retry: false, suspense: true } },
108112
})
113+
const queryClientV5 = new QueryClientV5({
114+
defaultOptions: { queries: { retry: false } },
115+
})
109116
const server = setupServer()
110117

111118
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
112-
<QueryClientProvider client={queryClient}>
113-
<MemoryRouter initialEntries={['/gh/test-org/test-repo/pull/12']}>
114-
<Route path="/:provider/:owner/:repo/pull/:pullId">
115-
<Suspense fallback={<p>Loading</p>}>{children}</Suspense>
116-
</Route>
117-
</MemoryRouter>
118-
</QueryClientProvider>
119+
<QueryClientProviderV5 client={queryClientV5}>
120+
<QueryClientProvider client={queryClient}>
121+
<MemoryRouter initialEntries={['/gh/test-org/test-repo/pull/12']}>
122+
<Route path="/:provider/:owner/:repo/pull/:pullId">
123+
<Suspense fallback={<p>Loading</p>}>{children}</Suspense>
124+
</Route>
125+
</MemoryRouter>
126+
</QueryClientProvider>
127+
</QueryClientProviderV5>
119128
)
120129

121130
beforeAll(() => {
122131
server.listen()
123132
})
124133
beforeEach(() => {
125-
server.resetHandlers()
126134
queryClient.clear()
135+
queryClientV5.clear()
136+
server.resetHandlers()
127137
})
128138
afterAll(() => {
129139
server.close()

src/pages/PullRequestPage/PullBundleAnalysis/PullBundleAnalysis.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useSuspenseQuery as useSuspenseQueryV5 } from '@tanstack/react-queryV5'
12
import { lazy, Suspense } from 'react'
23
import { useParams } from 'react-router-dom'
34

@@ -9,7 +10,10 @@ import BundleMessage from './BundleMessage'
910
import EmptyTable from './EmptyTable'
1011
import FirstPullBanner from './FirstPullBanner'
1112

12-
import { TBundleAnalysisComparisonResult, usePullPageData } from '../hooks'
13+
import {
14+
PullPageDataQueryOpts,
15+
TBundleAnalysisComparisonResult,
16+
} from '../queries/PullPageDataQueryOpts'
1317

1418
const PullBundleComparisonTable = lazy(
1519
() => import('./PullBundleComparisonTable')
@@ -82,13 +86,15 @@ const PullBundleAnalysis: React.FC = () => {
8286
const { provider, owner, repo, pullId } = useParams<URLParams>()
8387

8488
// we can set team plan true here because we don't care about the fields it will skip - tho we should really stop doing this and just return null on the API if they're on a team plan so we can save on requests made
85-
const { data } = usePullPageData({
86-
provider,
87-
owner,
88-
repo,
89-
pullId,
90-
isTeamPlan: true,
91-
})
89+
const { data } = useSuspenseQueryV5(
90+
PullPageDataQueryOpts({
91+
provider,
92+
owner,
93+
repo,
94+
pullId,
95+
isTeamPlan: true,
96+
})
97+
)
9298

9399
const bundleCompareType =
94100
data?.pull?.bundleAnalysisCompareWithBase?.__typename

src/pages/PullRequestPage/PullCoverage/PullCoverage.jsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useSuspenseQuery as useSuspenseQueryV5 } from '@tanstack/react-queryV5'
12
import { lazy, Suspense } from 'react'
23
import { Redirect, Switch, useParams } from 'react-router-dom'
34

@@ -14,7 +15,7 @@ import Spinner from 'ui/Spinner'
1415
import PullCoverageTabs from './PullCoverageTabs'
1516
import CompareSummarySkeleton from './Summary/CompareSummary/CompareSummarySkeleton'
1617

17-
import { usePullPageData } from '../hooks'
18+
import { PullPageDataQueryOpts } from '../queries/PullPageDataQueryOpts'
1819

1920
const CompareSummary = lazy(() => import('./Summary'))
2021
const FirstPullBanner = lazy(() => import('./FirstPullBanner'))
@@ -40,13 +41,15 @@ function PullCoverageContent() {
4041

4142
const isTeamPlan = tierData === TierNames.TEAM && overview?.private
4243

43-
const { data } = usePullPageData({
44-
provider,
45-
owner,
46-
repo,
47-
pullId,
48-
isTeamPlan,
49-
})
44+
const { data } = useSuspenseQueryV5(
45+
PullPageDataQueryOpts({
46+
provider,
47+
owner,
48+
repo,
49+
pullId,
50+
isTeamPlan,
51+
})
52+
)
5053

5154
const resultType = data?.pull?.compareWithBase?.__typename
5255

@@ -129,13 +132,15 @@ function PullCoverage() {
129132

130133
const isTeamPlan = tierData === TierNames.TEAM && overview?.private
131134

132-
const { data } = usePullPageData({
133-
provider,
134-
owner,
135-
repo,
136-
pullId,
137-
isTeamPlan,
138-
})
135+
const { data } = useSuspenseQueryV5(
136+
PullPageDataQueryOpts({
137+
provider,
138+
owner,
139+
repo,
140+
pullId,
141+
isTeamPlan,
142+
})
143+
)
139144

140145
return (
141146
<div className="mx-4 flex flex-col gap-4 md:mx-0">

src/pages/PullRequestPage/PullCoverage/PullCoverage.test.jsx

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
2+
import {
3+
QueryClientProvider as QueryClientProviderV5,
4+
QueryClient as QueryClientV5,
5+
} from '@tanstack/react-queryV5'
26
import { render, screen } from '@testing-library/react'
37
import { graphql, HttpResponse } from 'msw'
48
import { setupServer } from 'msw/node'
9+
import { Suspense } from 'react'
510
import { MemoryRouter, Route } from 'react-router-dom'
611

712
import { TierNames } from 'services/tier'
@@ -168,35 +173,41 @@ const mockRepoRateLimitStatus = ({ isGithubRateLimited = false }) => ({
168173
},
169174
})
170175

176+
const server = setupServer()
171177
const queryClient = new QueryClient({
178+
defaultOptions: { queries: { retry: false, suspense: true } },
179+
})
180+
const queryClientV5 = new QueryClientV5({
172181
defaultOptions: { queries: { retry: false } },
173182
})
174-
const server = setupServer()
175183

176184
const wrapper =
177185
(initialEntries = '/gh/codecov/test-repo/pull/1') =>
178186
({ children }) => (
179-
<QueryClientProvider client={queryClient}>
180-
<MemoryRouter initialEntries={[initialEntries]}>
181-
<Route
182-
path={[
183-
'/:provider/:owner/:repo/pull/:pullId/blob/:path+',
184-
'/:provider/:owner/:repo/pull/:pullId/tree/:path+',
185-
'/:provider/:owner/:repo/pull/:pullId/tree/',
186-
'/:provider/:owner/:repo/pull/:pullId',
187-
]}
188-
>
189-
{children}
190-
</Route>
191-
</MemoryRouter>
192-
</QueryClientProvider>
187+
<QueryClientProviderV5 client={queryClientV5}>
188+
<QueryClientProvider client={queryClient}>
189+
<MemoryRouter initialEntries={[initialEntries]}>
190+
<Route
191+
path={[
192+
'/:provider/:owner/:repo/pull/:pullId/blob/:path+',
193+
'/:provider/:owner/:repo/pull/:pullId/tree/:path+',
194+
'/:provider/:owner/:repo/pull/:pullId/tree/',
195+
'/:provider/:owner/:repo/pull/:pullId',
196+
]}
197+
>
198+
<Suspense fallback={<div>Loading</div>}>{children}</Suspense>
199+
</Route>
200+
</MemoryRouter>
201+
</QueryClientProvider>
202+
</QueryClientProviderV5>
193203
)
194204

195205
beforeAll(() => {
196206
server.listen()
197207
})
198208
afterEach(() => {
199209
queryClient.clear()
210+
queryClientV5.clear()
200211
server.resetHandlers()
201212
})
202213
afterAll(() => {

src/pages/PullRequestPage/PullCoverage/PullCoverageTabs/PullCoverageTabs.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useRepoOverview } from 'services/repo'
99
import { TierNames, useTier } from 'services/tier'
1010
import TabNavigation from 'ui/TabNavigation'
1111

12-
import { useTabsCounts } from './hooks'
12+
import { useTabsCounts } from './useTabsCounts'
1313

1414
function PullCoverageTabs() {
1515
const { provider, owner, repo, pullId } = useParams()

src/pages/PullRequestPage/PullCoverage/PullCoverageTabs/PullCoverageTabs.test.jsx

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
2+
import {
3+
QueryClientProvider as QueryClientProviderV5,
4+
QueryClient as QueryClientV5,
5+
} from '@tanstack/react-queryV5'
26
import { render, screen } from '@testing-library/react'
37
import { graphql, HttpResponse } from 'msw'
48
import { setupServer } from 'msw/node'
@@ -147,35 +151,41 @@ const mockBackfillResponse = {
147151
},
148152
}
149153

154+
const server = setupServer()
150155
const queryClient = new QueryClient({
151156
defaultOptions: { queries: { retry: false } },
152157
})
153-
const server = setupServer()
158+
const queryClientV5 = new QueryClientV5({
159+
defaultOptions: { queries: { retry: false } },
160+
})
154161

155162
const wrapper =
156163
(initialEntries = '/gh/codecov/test-repo/pull/1') =>
157164
({ children }) => (
158-
<QueryClientProvider client={queryClient}>
159-
<MemoryRouter initialEntries={[initialEntries]}>
160-
<Route
161-
path={[
162-
'/:provider/:owner/:repo/pull/:pullId',
163-
'/:provider/:owner/:repo/pull/:pullId/tree',
164-
'/:provider/:owner/:repo/pull/:pullId/tree/:path+',
165-
'/:provider/:owner/:repo/pull/:pullId/blob/:path+',
166-
]}
167-
>
168-
{children}
169-
</Route>
170-
</MemoryRouter>
171-
</QueryClientProvider>
165+
<QueryClientProviderV5 client={queryClientV5}>
166+
<QueryClientProvider client={queryClient}>
167+
<MemoryRouter initialEntries={[initialEntries]}>
168+
<Route
169+
path={[
170+
'/:provider/:owner/:repo/pull/:pullId',
171+
'/:provider/:owner/:repo/pull/:pullId/tree',
172+
'/:provider/:owner/:repo/pull/:pullId/tree/:path+',
173+
'/:provider/:owner/:repo/pull/:pullId/blob/:path+',
174+
]}
175+
>
176+
{children}
177+
</Route>
178+
</MemoryRouter>
179+
</QueryClientProvider>
180+
</QueryClientProviderV5>
172181
)
173182

174183
beforeAll(() => {
175184
server.listen()
176185
})
177186
afterEach(() => {
178187
queryClient.clear()
188+
queryClientV5.clear()
179189
server.resetHandlers()
180190
})
181191
afterAll(() => {

src/pages/PullRequestPage/PullCoverage/PullCoverageTabs/hooks/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)