Skip to content

Commit

Permalink
feat: enable/disable tabs and flag select based on team plan and priv…
Browse files Browse the repository at this point in the history
…ate repo status
  • Loading branch information
terry-codecov committed Nov 3, 2023
1 parent 581c691 commit b2c5b83
Show file tree
Hide file tree
Showing 9 changed files with 763 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const mockPullData = ({ resultType }: SetupArgs) => {
owner: {
repository: {
__typename: 'Repository',
private: false,
pull: {
pullId: 1,
head: {
Expand All @@ -60,6 +61,7 @@ const mockPullData = ({ resultType }: SetupArgs) => {
owner: {
repository: {
__typename: 'Repository',
private: false,
pull: {
pullId: 1,
head: {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/PullRequestPage/PullRequestPage.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const mockPullHeadData = {
owner: {
repository: {
__typename: 'Repository',
private: false,
pull: {
pullId: 12,
title: 'Cool New Pull Request',
Expand Down Expand Up @@ -91,6 +92,7 @@ describe('PullRequestPage', () => {
owner: {
repository: {
__typename: 'Repository',
private: false,
pull: pullData,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
pullFileviewString,
pullTreeviewString,
} from 'pages/PullRequestPage/utils'
import { TierNames, useTier } from 'services/tier'
import { useFlags } from 'shared/featureFlags'
import ToggleHeader from 'ui/FileViewer/ToggleHeader'
import TabNavigation from 'ui/TabNavigation'
Expand All @@ -18,13 +19,16 @@ function PullRequestPageTabs() {
indirectChangesCount,
directChangedFilesCount,
commitsCount,
isPrivateRepo,
} = useTabsCounts()
const { pullRequestPageFlagMultiSelect } = useFlags({
const { pullRequestPageFlagMultiSelect, multipleTiers } = useFlags({
pullRequestPageFlagMultiSelect: false,
multipleTiers: false,
})

const { pathname, search } = useLocation()
const { provider, owner, repo, pullId } = useParams()
const { data: tierData, isLoading } = useTier({ provider, owner })
const searchParams = qs.parse(search, { ignoreQueryPrefix: true })
const flags = searchParams?.flags ?? []

Expand All @@ -43,6 +47,53 @@ function PullRequestPageTabs() {
}
}

if (isLoading) {
return null
}

if (multipleTiers && tierData === TierNames.TEAM && isPrivateRepo) {
return (
<TabNavigation
tabs={[
{
pageName: 'pullDetail',
children: (
<>
Files changed
<sup className="text-xs">{directChangedFilesCount}</sup>
</>
),
options: { queryParams: { flags } },
exact: true,
},
{
pageName: 'pullCommits',
children: (
<>
Commits
<sup className="text-xs">{commitsCount}</sup>
</>
),
options: { queryParams: { flags } },
},
{
pageName: 'pullTreeView',
children: 'File explorer',
options: { pullId, queryParams: { flags } },
location: customLocation,
},
]}
component={
<ToggleHeader
coverageIsLoading={false}
showHitCount={true}
showFlagsSelect={false}
/>
}
/>
)
}

return (
<TabNavigation
tabs={[
Expand Down Expand Up @@ -108,7 +159,10 @@ function PullRequestPageTabs() {
<ToggleHeader
coverageIsLoading={false}
showHitCount={true}
showFlagsSelect={pullRequestPageFlagMultiSelect}
showFlagsSelect={
pullRequestPageFlagMultiSelect &&
(tierData !== TierNames.TEAM || !isPrivateRepo)
}
/>
}
/>
Expand Down
Loading

0 comments on commit b2c5b83

Please sign in to comment.