Skip to content

Commit 4ca8129

Browse files
authored
chore: Migrate useCommitPageData to TSQ V5 (#3537)
1 parent d4d8342 commit 4ca8129

File tree

9 files changed

+254
-153
lines changed

9 files changed

+254
-153
lines changed

src/pages/CommitDetailPage/CommitBundleAnalysis/CommitBundleAnalysis.test.tsx

Lines changed: 22 additions & 14 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'
@@ -127,23 +131,26 @@ const mockRepoOverview = ({
127131
})
128132

129133
const queryClient = new QueryClient({
130-
defaultOptions: {
131-
queries: { retry: false, suspense: true },
132-
},
134+
defaultOptions: { queries: { retry: false, suspense: true } },
135+
})
136+
const queryClientV5 = new QueryClientV5({
137+
defaultOptions: { queries: { retry: false } },
133138
})
134139

135140
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
136-
<QueryClientProvider client={queryClient}>
137-
<MemoryRouter
138-
initialEntries={[
139-
'/gh/test-org/test-repo/commit/e736f78b3cb5c8abb1d6b2ec5e5102de455f98ed',
140-
]}
141-
>
142-
<Route path="/:provider/:owner/:repo/commit/:commit">
143-
<Suspense fallback={<p>Loading...</p>}>{children}</Suspense>
144-
</Route>
145-
</MemoryRouter>
146-
</QueryClientProvider>
141+
<QueryClientProviderV5 client={queryClientV5}>
142+
<QueryClientProvider client={queryClient}>
143+
<MemoryRouter
144+
initialEntries={[
145+
'/gh/test-org/test-repo/commit/e736f78b3cb5c8abb1d6b2ec5e5102de455f98ed',
146+
]}
147+
>
148+
<Route path="/:provider/:owner/:repo/commit/:commit">
149+
<Suspense fallback={<p>Loading</p>}>{children}</Suspense>
150+
</Route>
151+
</MemoryRouter>
152+
</QueryClientProvider>
153+
</QueryClientProviderV5>
147154
)
148155

149156
const server = setupServer()
@@ -153,6 +160,7 @@ beforeAll(() => {
153160

154161
afterEach(() => {
155162
queryClient.clear()
163+
queryClientV5.clear()
156164
server.resetHandlers()
157165
})
158166

src/pages/CommitDetailPage/CommitBundleAnalysis/CommitBundleAnalysis.tsx

Lines changed: 13 additions & 7 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, useCommitPageData } from '../hooks'
13+
import {
14+
CommitPageDataQueryOpts,
15+
TBundleAnalysisComparisonResult,
16+
} from '../queries/CommitPageDataQueryOpts'
1317

1418
const CommitBundleAnalysisTable = lazy(
1519
() => import('./CommitBundleAnalysisTable')
@@ -63,12 +67,14 @@ const BundleContent: React.FC<BundleContentProps> = ({ bundleCompareType }) => {
6367

6468
const CommitBundleAnalysis: React.FC = () => {
6569
const { provider, owner, repo, commit: commitSha } = useParams<URLParams>()
66-
const { data: commitPageData } = useCommitPageData({
67-
provider,
68-
owner,
69-
repo,
70-
commitId: commitSha,
71-
})
70+
const { data: commitPageData } = useSuspenseQueryV5(
71+
CommitPageDataQueryOpts({
72+
provider,
73+
owner,
74+
repo,
75+
commitId: commitSha,
76+
})
77+
)
7278

7379
const bundleCompareType =
7480
commitPageData?.commit?.bundleAnalysis?.bundleAnalysisCompareWithParent

src/pages/CommitDetailPage/CommitCoverage/CommitCoverage.jsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useSuspenseQuery as useSuspenseQueryV5 } from '@tanstack/react-queryV5'
12
import isEmpty from 'lodash/isEmpty'
23
import { lazy, Suspense } from 'react'
34
import { Redirect, Switch, useParams } from 'react-router-dom'
@@ -22,7 +23,7 @@ import ErroredUploads from './ErroredUploads'
2223
import FirstPullBanner from './FirstPullBanner'
2324
import YamlErrorBanner from './YamlErrorBanner'
2425

25-
import { useCommitPageData } from '../hooks'
26+
import { CommitPageDataQueryOpts } from '../queries/CommitPageDataQueryOpts'
2627

2728
const CommitDetailFileExplorer = lazy(
2829
() => import('./routes/CommitDetailFileExplorer')
@@ -45,12 +46,14 @@ function CommitRoutes() {
4546
const { provider, owner, repo, commit: commitSha } = useParams()
4647
const { data: tierName } = useTier({ owner, provider })
4748
const { data: overview } = useRepoOverview({ provider, owner, repo })
48-
const { data: commitPageData } = useCommitPageData({
49-
provider,
50-
owner,
51-
repo,
52-
commitId: commitSha,
53-
})
49+
const { data: commitPageData } = useSuspenseQueryV5(
50+
CommitPageDataQueryOpts({
51+
provider,
52+
owner,
53+
repo,
54+
commitId: commitSha,
55+
})
56+
)
5457

5558
const compareTypeName = commitPageData?.commit?.compareWithParent?.__typename
5659
const ErrorBannerComponent = (
@@ -174,12 +177,14 @@ function CommitCoverage() {
174177
const { data: tierName } = useTier({ owner, provider })
175178
const { data: overview } = useRepoOverview({ provider, owner, repo })
176179
const { data: rateLimit } = useRepoRateLimitStatus({ provider, owner, repo })
177-
const { data: commitPageData } = useCommitPageData({
178-
provider,
179-
owner,
180-
repo,
181-
commitId: commitSha,
182-
})
180+
const { data: commitPageData } = useSuspenseQueryV5(
181+
CommitPageDataQueryOpts({
182+
provider,
183+
owner,
184+
repo,
185+
commitId: commitSha,
186+
})
187+
)
183188

184189
const showCommitSummary = !(overview.private && tierName === TierNames.TEAM)
185190
const showFirstPullBanner =

0 commit comments

Comments
 (0)