Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Remove tier name, use isTeamPlan #3666

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe('App', () => {
graphql.query('GetPlanData', () => {
return HttpResponse.json({ data: {} })
}),
graphql.query('OwnerTier', () => {
graphql.query('IsTeamPlan', () => {
return HttpResponse.json({ data: {} })
}),
graphql.query('Seats', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/AnalyticsPage/Chart/Chart.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ describe('Analytics coverage chart', () => {

return HttpResponse.json({ data: mockDataPoints })
}),
graphql.query('OwnerTier', () =>
HttpResponse.json({ data: { owner: { plan: { tierName: 'pro' } } } })
graphql.query('IsTeamPlan', () =>
HttpResponse.json({ data: { owner: { plan: { isTeamPlan: false } } } })
)
)
}
Expand Down
14 changes: 6 additions & 8 deletions src/pages/AnalyticsPage/Chart/useCoverage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'

import { TierNames, TTierNames } from 'services/tier'

import { useCoverage } from './useCoverage'

vi.mock('services/charts')
Expand Down Expand Up @@ -65,14 +63,14 @@ afterAll(() => {

interface SetupArgs {
nullFirstVal?: boolean
tierValue?: TTierNames
isTeamPlan?: boolean
}

describe('useCoverage', () => {
function setup(
{ nullFirstVal, tierValue }: SetupArgs = {
{ nullFirstVal, isTeamPlan }: SetupArgs = {
nullFirstVal: false,
tierValue: TierNames.PRO,
isTeamPlan: false,
}
) {
server.use(
Expand All @@ -85,9 +83,9 @@ describe('useCoverage', () => {
}
return HttpResponse.json({ data: mockRepoMeasurements })
}),
graphql.query('OwnerTier', () => {
graphql.query('IsTeamPlan', () => {
return HttpResponse.json({
data: { owner: { plan: { tierName: tierValue } } },
data: { owner: { plan: { isTeamPlan } } },
})
})
)
Expand Down Expand Up @@ -140,7 +138,7 @@ describe('useCoverage', () => {

describe('owner is on a team plan', () => {
it('gets public repos from useReposCoverageMeasurements', async () => {
setup({ tierValue: TierNames.TEAM })
setup({ isTeamPlan: true })
const { result } = renderHook(
() =>
useCoverage({
Expand Down
8 changes: 3 additions & 5 deletions src/pages/AnalyticsPage/Chart/useCoverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMemo } from 'react'
import { useParams } from 'react-router-dom'

import { useReposCoverageMeasurements } from 'services/charts/useReposCoverageMeasurements'
import { TierNames, useTier } from 'services/tier'
import { useIsTeamPlan } from 'services/useIsTeamPlan'
import { analyticsQuery } from 'shared/utils/timeseriesCharts'

interface URLParams {
Expand All @@ -28,9 +28,7 @@ export const useCoverage = ({
}: UseCoverageArgs) => {
const { provider, owner } = useParams<URLParams>()

const { data: tierName } = useTier({ provider, owner })
const shouldDisplayPublicReposOnly =
tierName === TierNames.TEAM ? true : undefined
const { data: isTeamPlan } = useIsTeamPlan({ provider, owner })

const queryVars = analyticsQuery({ startDate, endDate, repositories })

Expand All @@ -41,7 +39,7 @@ export const useCoverage = ({
repos: queryVars?.repositories,
before: queryVars?.endDate,
after: queryVars?.startDate,
isPublic: shouldDisplayPublicReposOnly,
isPublic: isTeamPlan ?? false,
opts: {
staleTime: 30000,
keepPreviousData: false,
Expand Down
11 changes: 5 additions & 6 deletions src/pages/AnalyticsPage/ChartSelectors/ChartSelectors.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useMemo, useRef, useState } from 'react'
import { useParams } from 'react-router-dom'

import { ReposQueryOpts } from 'services/repos/ReposQueryOpts'
import { TierNames, useTier } from 'services/tier'
import { useIsTeamPlan } from 'services/useIsTeamPlan'
import A from 'ui/A'
import DateRangePicker from 'ui/DateRangePicker'
import MultiSelect from 'ui/MultiSelect'
Expand Down Expand Up @@ -53,8 +53,7 @@ function RepoSelector({
updateParams({ repositories: item })
}

const { data: tierName } = useTier({ provider, owner })
const shouldDisplayPublicReposOnly = tierName === TierNames.TEAM ? true : null
const { data: isTeamPlan } = useIsTeamPlan({ provider, owner })

const {
data: reposData,
Expand All @@ -69,7 +68,7 @@ function RepoSelector({
activated: active,
term: search,
first: Infinity,
isPublic: shouldDisplayPublicReposOnly,
isPublic: isTeamPlan,
})
)

Expand Down Expand Up @@ -114,7 +113,7 @@ function ChartSelectors({ params, updateParams, active, sortItem }) {
const { repositories, startDate, endDate } = params
const [selectedRepos, setSelectedRepos] = useState(repositories)

const { data: tierData } = useTier({ provider, owner })
const { data: isTeamPlan } = useIsTeamPlan({ provider, owner })

if (selectedRepos.length > 0 && repositories.length === 0) {
setSelectedRepos([])
Expand Down Expand Up @@ -151,7 +150,7 @@ function ChartSelectors({ params, updateParams, active, sortItem }) {
>
Clear filters
</button>
{tierData === TierNames.TEAM ? (
{isTeamPlan ? (
<p className="self-end">
Public repos only. <A to={{ pageName: 'upgradeOrgPlan' }}>Upgrade</A>{' '}
to Pro to include private repos.
Expand Down
10 changes: 4 additions & 6 deletions src/pages/AnalyticsPage/ChartSelectors/ChartSelectors.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { setupServer } from 'msw/node'
import { Suspense } from 'react'
import { MemoryRouter, Route } from 'react-router-dom'

import { TierNames } from 'services/tier'

import ChartSelectors from './ChartSelectors'

class ResizeObserverMock {
Expand Down Expand Up @@ -127,16 +125,16 @@ describe('ChartSelectors', () => {
vi.clearAllMocks()
})

function setup({ hasNextPage = false, tierValue = TierNames.PRO }) {
function setup({ hasNextPage = false, isTeamPlan = false }) {
// https://github.com/testing-library/user-event/issues/1034
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime })
const fetchNextPage = vi.fn()
const searchTerm = vi.fn()

server.use(
graphql.query('OwnerTier', () => {
graphql.query('IsTeamPlan', () => {
return HttpResponse.json({
data: { owner: { plan: { tierName: tierValue } } },
data: { owner: { plan: { isTeamPlan } } },
})
}),
graphql.query('ReposForOwner', ({ variables }) => {
Expand Down Expand Up @@ -526,7 +524,7 @@ describe('ChartSelectors', () => {

describe('owner is on a team plan', () => {
it('renders upgrade cta', async () => {
setup({ hasNextPage: false, tierValue: TierNames.TEAM })
setup({ hasNextPage: false, isTeamPlan: true })
render(
<ChartSelectors
active={true}
Expand Down
10 changes: 5 additions & 5 deletions src/pages/CommitDetailPage/CommitCoverage/CommitCoverage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SentryRoute } from 'sentry'
import { useCommit } from 'services/commit'
import { useCommitErrors } from 'services/commitErrors'
import { useRepoOverview, useRepoRateLimitStatus } from 'services/repo'
import { TierNames, useTier } from 'services/tier'
import { useIsTeamPlan } from 'services/useIsTeamPlan'
import { useOwner } from 'services/user'
import ComparisonErrorBanner from 'shared/ComparisonErrorBanner'
import GitHubRateLimitExceededBanner from 'shared/GlobalBanners/GitHubRateLimitExceeded/GitHubRateLimitExceededBanner'
Expand Down Expand Up @@ -44,7 +44,7 @@ const Loader = () => (

function CommitRoutes() {
const { provider, owner, repo, commit: commitSha } = useParams()
const { data: tierName } = useTier({ owner, provider })
const { data: isTeamPlan } = useIsTeamPlan({ owner, provider })
const { data: overview } = useRepoOverview({ provider, owner, repo })
const { data: commitPageData } = useSuspenseQueryV5(
CommitPageDataQueryOpts({
Expand Down Expand Up @@ -74,7 +74,7 @@ function CommitRoutes() {
// is still useful info to the user
const isMissingBaseCommit = compareTypeName === 'MissingBaseCommit'

const showIndirectChanges = !(overview.private && tierName === TierNames.TEAM)
const showIndirectChanges = !(overview.private && isTeamPlan)

return (
<Suspense fallback={<Loader />}>
Expand Down Expand Up @@ -174,7 +174,7 @@ function CommitCoverageRoutes() {

function CommitCoverage() {
const { provider, owner, repo, commit: commitSha } = useParams()
const { data: tierName } = useTier({ owner, provider })
const { data: isTeamPlan } = useIsTeamPlan({ owner, provider })
const { data: overview } = useRepoOverview({ provider, owner, repo })
const { data: rateLimit } = useRepoRateLimitStatus({ provider, owner, repo })
const { data: commitPageData } = useSuspenseQueryV5(
Expand All @@ -186,7 +186,7 @@ function CommitCoverage() {
})
)

const showCommitSummary = !(overview.private && tierName === TierNames.TEAM)
const showCommitSummary = !(overview.private && isTeamPlan)
const showFirstPullBanner =
commitPageData?.commit?.compareWithParent?.__typename === 'FirstPullRequest'
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { setupServer } from 'msw/node'
import { Suspense } from 'react'
import { MemoryRouter, Route } from 'react-router-dom'

import { TierNames } from 'services/tier/useTier'
import { UploadStateEnum } from 'shared/utils/commit'

import CommitCoverage from './CommitCoverage'
Expand Down Expand Up @@ -199,10 +198,10 @@ const mockRepoSettingsTeamData = (isPrivate = false) => ({
},
})

const mockOwnerTier = (tier = TierNames.PRO) => ({
const mockIsTeamPlan = (isTeamPlan = false) => ({
owner: {
plan: {
tierName: tier,
isTeamPlan,
},
},
})
Expand Down Expand Up @@ -396,7 +395,7 @@ describe('CommitCoverage', () => {
function setup(
{
isPrivate = false,
tierName = TierNames.PRO,
isTeamPlan = false,
hasCommitErrors = false,
hasErroredUploads = false,
hasCommitPageMissingCommitDataError = false,
Expand All @@ -407,7 +406,7 @@ describe('CommitCoverage', () => {
isGithubRateLimited = false,
} = {
isPrivate: false,
tierName: TierNames.PRO,
isTeamPlan: false,
hasCommitErrors: false,
hasErroredUploads: false,
hasCommitPageMissingCommitDataError: false,
Expand Down Expand Up @@ -443,8 +442,8 @@ describe('CommitCoverage', () => {
}),
})
}),
graphql.query('OwnerTier', () => {
return HttpResponse.json({ data: mockOwnerTier(tierName) })
graphql.query('IsTeamPlan', () => {
return HttpResponse.json({ data: mockIsTeamPlan(isTeamPlan) })
}),
graphql.query('BackfillFlagMemberships', () => {
return HttpResponse.json({ data: mockRepoBackfilledData })
Expand Down Expand Up @@ -582,7 +581,7 @@ describe('CommitCoverage', () => {
describe('user is on a team plan', () => {
it('does not render commit coverage summary', async () => {
const { queryClient, queryClientV5 } = setup({
tierName: TierNames.TEAM,
isTeamPlan: true,
isPrivate: true,
})
render(<CommitCoverage />, {
Expand All @@ -598,7 +597,7 @@ describe('CommitCoverage', () => {

it('does not render indirect changes tab', async () => {
const { queryClient, queryClientV5 } = setup({
tierName: TierNames.TEAM,
isTeamPlan: true,
isPrivate: true,
})
render(<CommitCoverage />, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
commitTreeviewString,
} from 'pages/RepoPage/utils'
import { useRepoSettingsTeam } from 'services/repo'
import { TierNames, useTier } from 'services/tier'
import { useIsTeamPlan } from 'services/useIsTeamPlan'
import TabNavigation from 'ui/TabNavigation'

function CommitCoverageTabs({
Expand All @@ -18,12 +18,10 @@ function CommitCoverageTabs({
}) {
const { provider, owner, repo } = useParams()
const location = useLocation()
const { data: tierName } = useTier({ owner, provider })
const { data: isTeamPlan } = useIsTeamPlan({ owner, provider })
const { data: repoData } = useRepoSettingsTeam()

const showIndirectChanges = !(
repoData?.repository?.private && tierName === TierNames.TEAM
)
const showIndirectChanges = !(repoData?.repository?.private && isTeamPlan)

const params = qs.parse(location.search, {
ignoreQueryPrefix: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import qs from 'qs'
import { Suspense } from 'react'
import { MemoryRouter, Route } from 'react-router-dom'

import { TierNames } from 'services/tier'

import CommitCoverageTabs from './CommitCoverageTabs'

const mockRepoSettings = (isPrivate) => ({
Expand Down Expand Up @@ -110,22 +108,17 @@ afterAll(() => {
})

describe('CommitCoverageTabs', () => {
function setup(
{ tierValue = TierNames.PRO, isPrivate = false } = {
tierValue: TierNames.PRO,
isPrivate: false,
}
) {
function setup({ isTeamPlan = false, isPrivate = false } = {}) {
server.use(
graphql.query('FlagsSelect', () => {
return HttpResponse.json({ data: mockFlagsResponse })
}),
graphql.query('BackfillFlagMemberships', () => {
return HttpResponse.json({ data: mockBackfillResponse })
}),
graphql.query('OwnerTier', () => {
graphql.query('IsTeamPlan', () => {
return HttpResponse.json({
data: { owner: { plan: { tierName: tierValue } } },
data: { owner: { plan: { isTeamPlan } } },
})
}),
graphql.query('GetRepoSettingsTeam', () => {
Expand All @@ -137,7 +130,7 @@ describe('CommitCoverageTabs', () => {
describe('user is on a team plan', () => {
describe('repo is public', () => {
it('does not render the indirect changes tab', async () => {
setup({ tierValue: TierNames.TEAM, isPrivate: false })
setup({ isTeamPlan: true, isPrivate: false })
render(<CommitCoverageTabs commitSha="sha256" />, {
wrapper: wrapper(),
})
Expand All @@ -154,7 +147,7 @@ describe('CommitCoverageTabs', () => {
})
describe('repo is private', () => {
it('does not render the indirect changes tab', async () => {
setup({ tierValue: TierNames.TEAM, isPrivate: true })
setup({ isTeamPlan: true, isPrivate: true })
render(<CommitCoverageTabs commitSha="sha256" />, {
wrapper: wrapper(),
})
Expand Down
Loading
Loading