Skip to content

Commit a688ddd

Browse files
Merge branch 'main' into cy/modal_classname
2 parents d672691 + b53522f commit a688ddd

File tree

4 files changed

+59
-32
lines changed

4 files changed

+59
-32
lines changed

src/pages/OwnerPage/OwnerPage.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ function OwnerPage() {
9090
</Suspense>
9191
<div>
9292
{showOnboardingContainer ? <OnboardingOrg /> : null}
93-
{ownerData?.isCurrentUserPartOfOrg && (
93+
{ownerData?.isCurrentUserPartOfOrg ? (
9494
<Tabs owner={ownerData} provider={provider} />
95-
)}
95+
) : null}
9696
<ActiveContext.Provider value={params?.repoDisplay}>
9797
<ListRepo
98-
canRefetch={ownerData?.isCurrentUserPartOfOrg}
98+
canRefetch={!!ownerData?.isCurrentUserPartOfOrg}
9999
hasGhApp={hasGhApp}
100100
/>
101101
</ActiveContext.Provider>

src/shared/ListRepo/ListRepo.test.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ const wrapper =
127127

128128
describe('ListRepo', () => {
129129
function setup(
130-
{ isTeamPlan = false }: { isTeamPlan?: boolean },
130+
{
131+
isTeamPlan = false,
132+
isAdmin = true,
133+
}: { isTeamPlan?: boolean; isAdmin?: boolean },
131134
me = mockUser
132135
) {
133136
const user = userEvent.setup()
@@ -140,6 +143,11 @@ describe('ListRepo', () => {
140143
}),
141144
graphql.query('CurrentUser', () => {
142145
return HttpResponse.json({ data: me })
146+
}),
147+
graphql.query('DetailOwner', () => {
148+
return HttpResponse.json({
149+
data: { owner: { username: 'janedoe', isAdmin } },
150+
})
143151
})
144152
)
145153

@@ -329,5 +337,27 @@ describe('ListRepo', () => {
329337
expect(banner).not.toBeInTheDocument()
330338
})
331339
})
340+
it('does not display github app config banner if isAdmin is false', async () => {
341+
setup({ isAdmin: false })
342+
render(<ListRepo canRefetch hasGhApp={false} />, {
343+
wrapper: wrapper({
344+
url: '/gh/janedoe',
345+
path: '/:provider/:owner',
346+
}),
347+
})
348+
const banner = screen.queryByText("Codecov's GitHub app")
349+
expect(banner).not.toBeInTheDocument()
350+
})
351+
})
352+
describe('user has gh app installed', () => {
353+
it('does not display github app config banner if hasGhApp is true', async () => {
354+
setup({})
355+
render(<ListRepo canRefetch hasGhApp={true} />, {
356+
wrapper: wrapper({
357+
url: '/gh/janedoe',
358+
path: '/:provider/:owner',
359+
}),
360+
})
361+
})
332362
})
333363
})

src/shared/ListRepo/ListRepo.jsx renamed to src/shared/ListRepo/ListRepo.tsx

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* */
2-
import PropTypes from 'prop-types'
31
import { Suspense, useContext } from 'react'
42
import { useParams } from 'react-router-dom'
53

@@ -8,7 +6,8 @@ import { ONBOARDING_SOURCE } from 'pages/TermsOfService/constants'
86
import { useLocationParams } from 'services/navigation'
97
import { orderingOptions } from 'services/repos/orderingOptions'
108
import { useIsTeamPlan } from 'services/useIsTeamPlan'
11-
import { useUser } from 'services/user'
9+
import { useIsCurrentUserAnAdmin, useUser } from 'services/user'
10+
import { Provider } from 'shared/api/helpers'
1211
import { ActiveContext } from 'shared/context'
1312
import { Alert } from 'ui/Alert'
1413
import Spinner from 'ui/Spinner'
@@ -30,40 +29,47 @@ export const repoDisplayOptions = Object.freeze({
3029
ALL: { text: 'All', status: undefined },
3130
})
3231

33-
function ListRepo({ canRefetch, hasGhApp }) {
34-
const { provider, owner } = useParams()
32+
interface ListRepoProps {
33+
canRefetch: boolean
34+
hasGhApp?: boolean
35+
}
36+
37+
interface URLParams {
38+
provider: Provider
39+
owner: string
40+
}
41+
42+
function ListRepo({ canRefetch, hasGhApp }: ListRepoProps) {
43+
const { provider, owner } = useParams<URLParams>()
3544
const { params, updateParams } = useLocationParams(defaultQueryParams)
45+
// @ts-expect-error useLocationParams needs to be typed
46+
const { search, source } = params
3647
const { data: isTeamPlan } = useIsTeamPlan({ provider, owner })
3748
const { data: currentUser } = useUser({
3849
options: {
3950
suspense: false,
4051
},
4152
})
53+
const isAdmin = useIsCurrentUserAnAdmin({ owner })
4254

4355
const repoDisplay = useContext(ActiveContext)
4456

45-
const sortItem = orderingOptions.find(
46-
(option) =>
47-
option.ordering === params.ordering &&
48-
option.direction === params.direction
49-
)
50-
5157
const loadingState = (
5258
<div className="flex justify-center py-8">
5359
<Spinner />
5460
</div>
5561
)
5662

57-
const cameFromOnboarding = params['source'] === ONBOARDING_SOURCE
63+
const cameFromOnboarding = source === ONBOARDING_SOURCE
5864
const isMyOwnerPage = currentUser?.user?.username === owner
5965
const showDemoAlert = cameFromOnboarding && isMyOwnerPage
6066

6167
return (
6268
<>
63-
{/* we only want one of these two banners to show at a time */}
64-
{!hasGhApp && !showDemoAlert && <GithubConfigBanner />}
69+
{/* we only want one of this or DemoAlert banners to show at a time */}
70+
{isAdmin && !hasGhApp && !showDemoAlert ? <GithubConfigBanner /> : null}
6571
<OrgControlTable
66-
searchValue={params.search}
72+
searchValue={search}
6773
repoDisplay={repoDisplay}
6874
setRepoDisplay={(repoDisplay) =>
6975
updateParams({
@@ -90,23 +96,13 @@ function ListRepo({ canRefetch, hasGhApp }) {
9096

9197
<Suspense fallback={loadingState}>
9298
{isTeamPlan ? (
93-
<ReposTableTeam searchValue={params.search} />
99+
<ReposTableTeam searchValue={search} />
94100
) : (
95-
<ReposTable
96-
sortItem={sortItem}
97-
owner={owner}
98-
searchValue={params.search}
99-
mayIncludeDemo
100-
/>
101+
<ReposTable owner={owner} searchValue={search} mayIncludeDemo />
101102
)}
102103
</Suspense>
103104
</>
104105
)
105106
}
106107

107-
ListRepo.propTypes = {
108-
canRefetch: PropTypes.bool.isRequired,
109-
hasGhApp: PropTypes.bool,
110-
}
111-
112108
export default ListRepo

src/ui/Icon/svg/outline/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ import search from './search.svg?react'
185185
// import shoppingCart from './shopping-cart.svg?react'
186186
// import sortAscending from './sort-ascending.svg?react'
187187
// import sortDescending from './sort-descending.svg?react'
188-
// import sparkles from './sparkles.svg?react'
188+
import sparkles from './sparkles.svg?react'
189189
import speakerphone from './speakerphone.svg?react'
190190
// import star from './star.svg?react'
191191
// import statusOffline from './status-offline.svg?react'
@@ -266,6 +266,7 @@ export {
266266
questionMarkCircle,
267267
refresh,
268268
search,
269+
sparkles,
269270
speakerphone,
270271
sun,
271272
trash,

0 commit comments

Comments
 (0)