Skip to content

Commit 9034486

Browse files
fix: Pin demo repo to top during sort (#3598)
1 parent 358f6ec commit 9034486

File tree

2 files changed

+111
-31
lines changed

2 files changed

+111
-31
lines changed

src/shared/ListRepo/ReposTable/ReposTable.test.tsx

Lines changed: 92 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -913,53 +913,129 @@ describe('ReposTable', () => {
913913
name: 'Repo name 1',
914914
latestCommitAt: subDays(new Date(), 3).toISOString(),
915915
coverageAnalytics: {
916-
percentCovered: 0,
916+
percentCovered: 10,
917917
lines: 123,
918918
},
919919
active: true,
920920
updatedAt: '2020-08-25T16:36:19.67986800:00',
921921
repositoryConfig: null,
922-
coverageEnabled: false,
922+
coverageEnabled: true,
923923
bundleAnalysisEnabled: false,
924924
},
925925
},
926+
]
927+
928+
let reposToReturn = myRepos.filter(
929+
(repo) =>
930+
!info.variables.filters.term ||
931+
repo.node.name.includes(info.variables.filters.term)
932+
)
933+
934+
if (info.variables.owner === 'codecov') {
935+
reposToReturn = demoRepo
936+
}
937+
938+
return HttpResponse.json({
939+
data: {
940+
owner: {
941+
repositories: {
942+
edges: reposToReturn,
943+
pageInfo: {
944+
hasNextPage: false,
945+
endCursor: '3',
946+
},
947+
},
948+
},
949+
},
950+
})
951+
})
952+
)
953+
})
954+
955+
it('shows demo repo and your repos when on your owner page', async () => {
956+
render(<ReposTable searchValue="" owner="owner1" mayIncludeDemo />, {
957+
wrapper: wrapper('', '/github/owner1', '/:provider/:owner'),
958+
})
959+
const demoLink = await screen.findAllByText(/Codecov demo/)
960+
expect(demoLink.length).toBe(1)
961+
const links = await screen.findAllByText(/Repo name/)
962+
expect(links.length).toBe(1)
963+
})
964+
965+
it('shows demo repo when search term includes it', async () => {
966+
render(<ReposTable searchValue="dem" owner="owner1" mayIncludeDemo />, {
967+
wrapper: wrapper('', '/github/owner1', '/:provider/:owner'),
968+
})
969+
const repo = screen.queryByText(/Repo name/)
970+
expect(repo).not.toBeInTheDocument()
971+
const demoLink = await screen.findAllByText(/Codecov demo/)
972+
expect(demoLink.length).toBe(1)
973+
})
974+
975+
it('hides demo repo when user has 2 or more repos configured', async () => {
976+
server.use(
977+
graphql.query('ReposForOwner', async (info) => {
978+
const demoRepo = [
926979
{
927980
node: {
928-
private: true,
981+
private: false,
929982
activated: true,
983+
author: {
984+
username: 'codecov',
985+
},
986+
name: 'gazebo',
987+
latestCommitAt: subDays(new Date(), 3).toISOString(),
988+
coverageAnalytics: {
989+
percentCovered: 0,
990+
lines: 123,
991+
},
992+
active: true,
993+
updatedAt: '2020-08-25T16:36:19.67986800:00',
994+
repositoryConfig: null,
995+
coverageEnabled: true,
996+
bundleAnalysisEnabled: true,
997+
},
998+
},
999+
]
1000+
1001+
const myRepos = [
1002+
{
1003+
node: {
1004+
private: false,
1005+
activated: false,
9301006
author: {
9311007
username: 'owner1',
9321008
},
933-
name: 'Repo name 2',
934-
latestCommitAt: subDays(new Date(), 2).toISOString(),
1009+
name: 'Repo name 1',
1010+
latestCommitAt: subDays(new Date(), 3).toISOString(),
9351011
coverageAnalytics: {
936-
percentCovered: 100,
1012+
percentCovered: 10,
9371013
lines: 123,
9381014
},
9391015
active: true,
9401016
updatedAt: '2020-08-25T16:36:19.67986800:00',
9411017
repositoryConfig: null,
942-
coverageEnabled: false,
1018+
coverageEnabled: true,
9431019
bundleAnalysisEnabled: false,
9441020
},
9451021
},
9461022
{
9471023
node: {
948-
private: true,
1024+
private: false,
9491025
activated: false,
9501026
author: {
9511027
username: 'owner1',
9521028
},
953-
name: 'Repo name 3',
954-
latestCommitAt: subDays(new Date(), 5).toISOString(),
1029+
name: 'Repo name 1',
1030+
latestCommitAt: subDays(new Date(), 3).toISOString(),
9551031
coverageAnalytics: {
956-
percentCovered: null,
1032+
percentCovered: 0,
9571033
lines: 123,
9581034
},
959-
active: false,
1035+
active: true,
9601036
updatedAt: '2020-08-25T16:36:19.67986800:00',
9611037
repositoryConfig: null,
962-
coverageEnabled: false,
1038+
coverageEnabled: true,
9631039
bundleAnalysisEnabled: false,
9641040
},
9651041
},
@@ -990,26 +1066,13 @@ describe('ReposTable', () => {
9901066
})
9911067
})
9921068
)
993-
})
994-
995-
it('shows demo repo and your repos when on your owner page', async () => {
9961069
render(<ReposTable searchValue="" owner="owner1" mayIncludeDemo />, {
9971070
wrapper: wrapper('', '/github/owner1', '/:provider/:owner'),
9981071
})
9991072
const links = await screen.findAllByText(/Repo name/)
1000-
expect(links.length).toBe(3)
1001-
const demoLink = await screen.findAllByText(/Codecov demo/)
1002-
expect(demoLink.length).toBe(1)
1003-
})
1004-
1005-
it('shows demo repo when search term includes it', async () => {
1006-
render(<ReposTable searchValue="dem" owner="owner1" mayIncludeDemo />, {
1007-
wrapper: wrapper('', '/github/owner1', '/:provider/:owner'),
1008-
})
1009-
const repo = screen.queryByText(/Repo name/)
1010-
expect(repo).not.toBeInTheDocument()
1011-
const demoLink = await screen.findAllByText(/Codecov demo/)
1012-
expect(demoLink.length).toBe(1)
1073+
expect(links.length).toBe(2)
1074+
const demoLink = screen.queryAllByText(/Codecov demo/)
1075+
expect(demoLink.length).toBe(0)
10131076
})
10141077
})
10151078
})

src/shared/ListRepo/ReposTable/ReposTable.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,34 @@ const ReposTable = ({
153153
})
154154

155155
const isMyOwnerPage = currentUser?.user?.username === owner
156-
const includeDemo = mayIncludeDemo && !config.IS_SELF_HOSTED && isMyOwnerPage
157156

158157
const tableData = useMemo(() => {
159158
const repos =
160159
reposData?.pages.flatMap((page) => page?.repos).filter(isNotNull) ?? []
161160

161+
const configuredRepos = repos.reduce(
162+
(acc, repo) => (repo.coverageEnabled ? acc + 1 : acc),
163+
0
164+
)
165+
166+
const includeDemo =
167+
mayIncludeDemo &&
168+
!config.IS_SELF_HOSTED &&
169+
isMyOwnerPage &&
170+
configuredRepos < 2
171+
162172
const demoRepos = includeDemo
163173
? formatDemoRepos(demoReposData, searchValue)
164174
: []
165175

166176
return [...demoRepos, ...repos]
167-
}, [reposData?.pages, demoReposData, includeDemo, searchValue])
177+
}, [
178+
reposData?.pages,
179+
demoReposData,
180+
searchValue,
181+
isMyOwnerPage,
182+
mayIncludeDemo,
183+
])
168184

169185
useEffect(() => {
170186
if (inView && hasNextPage) {
@@ -186,6 +202,7 @@ const ReposTable = ({
186202
onSortingChange: setSorting,
187203
getSortedRowModel: getSortedRowModel(),
188204
enableSortingRemoval: false,
205+
manualSorting: true,
189206
})
190207

191208
if (!isReposLoading && isEmpty(tableData)) {

0 commit comments

Comments
 (0)