Skip to content

Commit

Permalink
update CoverageChart to use updated useRepoCoverageTimeseries
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov committed Feb 6, 2025
1 parent 5f6cdbf commit 5812194
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import {
QueryClientProvider as QueryClientProviderV5,
QueryClient as QueryClientV5,
} from '@tanstack/react-queryV5'
import { render, screen, within } from '@testing-library/react'
import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
Expand Down Expand Up @@ -26,21 +30,27 @@ vi.mock('recharts', async () => {
}
})

const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
})
const queryClientV5 = new QueryClientV5({
defaultOptions: { queries: { retry: false } },
})

const wrapper =
(
initialEntries = ['/gh/codecov/bells-hells/tree/main']
): React.FC<React.PropsWithChildren> =>
({ children }) => (
<QueryClientProvider client={queryClient}>
<MemoryRouter initialEntries={initialEntries}>
<Route path="/:provider/:owner/:repo">{children}</Route>
</MemoryRouter>
</QueryClientProvider>
<QueryClientProviderV5 client={queryClientV5}>
<QueryClientProvider client={queryClient}>
<MemoryRouter initialEntries={initialEntries}>
<Route path="/:provider/:owner/:repo">{children}</Route>
</MemoryRouter>
</QueryClientProvider>
</QueryClientProviderV5>
)

const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
})
const server = setupServer()

beforeAll(() => {
Expand Down Expand Up @@ -73,6 +83,7 @@ beforeEach(() => {

afterEach(() => {
queryClient.clear()
queryClientV5.clear()
server.resetHandlers()
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { keepPreviousData } from '@tanstack/react-queryV5'
import { format } from 'date-fns'
import { useParams } from 'react-router-dom'
import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from 'recharts'
Expand Down Expand Up @@ -43,17 +44,16 @@ function CoverageChart() {
defaultBranch: overview?.defaultBranch ?? '',
})

const { data, isPreviousData, isLoading, isError } =
const { data, isPlaceholderData, isPending, isError } =
useRepoCoverageTimeseries({
branch: selection?.name,
options: {
enabled: !!selection?.name,
suspense: false,
keepPreviousData: true,
placeholderData: keepPreviousData,
},
})

if (!isPreviousData && isLoading) {
if (!isPlaceholderData && isPending) {
return <Placeholder />
}

Expand All @@ -65,7 +65,7 @@ function CoverageChart() {
)
}

if (data?.measurements.length < 1) {
if (!isPending && data?.measurements?.length < 1) {
return (
<div className="flex min-h-[250px] items-center justify-center xl:min-h-[380px]">
<p className="text-center">
Expand Down

0 comments on commit 5812194

Please sign in to comment.