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

Refactor Repos table in owner page and analytics page #2518

Merged
merged 28 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c8a7ddd
Formatting
rohitvinnakota-codecov Jan 16, 2024
46786cf
update test
rohitvinnakota-codecov Jan 16, 2024
a96b214
add userepos test
rohitvinnakota-codecov Jan 16, 2024
b309f95
remove sorting tests
rohitvinnakota-codecov Jan 16, 2024
c43f336
remove spec
rohitvinnakota-codecov Jan 16, 2024
c384852
Add tests to useRepos
rohitvinnakota-codecov Jan 17, 2024
a32958d
Add wait for
rohitvinnakota-codecov Jan 17, 2024
3b62daf
Remove extra params
rohitvinnakota-codecov Jan 17, 2024
c4e9fc3
update chart selectors
rohitvinnakota-codecov Jan 17, 2024
e1232e5
Fix css
rohitvinnakota-codecov Jan 17, 2024
3936d02
chart selector tests
rohitvinnakota-codecov Jan 17, 2024
13f0f6a
Merge branch 'main' into rvinnakota/refactor-repo-table
rohitvinnakota-codecov Jan 17, 2024
261dd36
remove log
rohitvinnakota-codecov Jan 17, 2024
f4ffa5b
Merge branch 'rvinnakota/refactor-repo-table' of https://github.com/c…
rohitvinnakota-codecov Jan 17, 2024
f24d46e
Remove ordering options
rohitvinnakota-codecov Jan 17, 2024
f2cbbb9
Merge branch 'main' of https://github.com/codecov/gazebo into rvinnak…
rohitvinnakota-codecov Jan 26, 2024
5ac4e04
update sorting
rohitvinnakota-codecov Jan 26, 2024
9d931ff
Merge branch 'main' of https://github.com/codecov/gazebo into rvinnak…
rohitvinnakota-codecov Jan 29, 2024
63cf49b
Merge branch 'main' of https://github.com/codecov/gazebo into rvinnak…
rohitvinnakota-codecov Jan 29, 2024
47aafdf
Test infinite scroll
rohitvinnakota-codecov Jan 29, 2024
2316124
switch to isLoading
rohitvinnakota-codecov Jan 30, 2024
ca7bc6f
define variable type
rohitvinnakota-codecov Jan 30, 2024
23601e1
Add sort tests
rohitvinnakota-codecov Jan 30, 2024
a849ea1
Additional tests
rohitvinnakota-codecov Jan 30, 2024
0d2eb41
Reformat queries
rohitvinnakota-codecov Feb 5, 2024
76f4f09
Merge branch 'main' of https://github.com/codecov/gazebo into rvinnak…
rohitvinnakota-codecov Feb 5, 2024
0049dea
Use first
rohitvinnakota-codecov Feb 5, 2024
9bcaffd
Merge branch 'main' into rvinnakota/refactor-repo-table
rohitvinnakota-codecov Feb 6, 2024
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
16 changes: 13 additions & 3 deletions src/pages/AnalyticsPage/ChartSelectors/ChartSelectors.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PropTypes from 'prop-types'
import { useRef, useState } from 'react'
import { useMemo, useRef, useState } from 'react'
import { useParams } from 'react-router-dom'

import { useRepos } from 'services/repos'
Expand Down Expand Up @@ -55,7 +55,12 @@ function RepoSelector({
const { data: tierName } = useTier({ provider, owner })
const shouldDisplayPublicReposOnly = tierName === TierNames.TEAM ? true : null

const { data, isLoading, fetchNextPage, hasNextPage } = useRepos({
const {
data: reposData,
isLoading,
fetchNextPage,
hasNextPage,
} = useRepos({
activated: active,
sortItem,
term: search,
Expand All @@ -65,14 +70,19 @@ function RepoSelector({
isPublic: shouldDisplayPublicReposOnly,
})

const reposSelectData = useMemo(() => {
const data = reposData?.pages?.map((page) => page?.repos).flat()
return data ?? []
}, [reposData?.pages])

return (
<div className="flex w-52 flex-col gap-2">
<span className="font-semibold">Repositories</span>
<MultiSelect
hook="repo-chart-selector"
ariaName="Select repos to choose"
dataMarketing="repo-chart-selector"
items={formatDataForMultiselect(data?.repos)}
items={formatDataForMultiselect(reposSelectData)}
onChange={onSelectChangeHandler}
resourceName="Repo"
value={selectedRepos}
Expand Down
38 changes: 24 additions & 14 deletions src/pages/AnalyticsPage/ChartSelectors/ChartSelectors.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,26 @@ afterAll(() => {
describe('ChartSelectors', () => {
afterEach(() => jest.resetAllMocks())

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

const fetchNextPage = jest.fn()

useRepos.mockReturnValue({
data: { repos: repositories },
data: {
pages: [
{
repos: repositories,
pageInfo: {
hasNextPage: true,
endCursor: 'MjAyMC0wOC0xMSAxNzozMDowMiswMDowMHwxMDA=',
},
},
],
},
fetchNextPage,
hasNextPage: useReposMock?.hasNextPage || true,
hasNextPage,
})

server.use(
Expand All @@ -107,7 +117,7 @@ describe('ChartSelectors', () => {
}

describe('renders component', () => {
beforeEach(() => setup())
beforeEach(() => setup({}))

it('renders date picker', async () => {
render(
Expand Down Expand Up @@ -166,7 +176,7 @@ describe('ChartSelectors', () => {

describe('interacting with the date picker', () => {
it('updates the location params', async () => {
const { user } = setup()
const { user } = setup({})
const updateParams = jest.fn()
render(
<ChartSelectors
Expand Down Expand Up @@ -202,7 +212,7 @@ describe('ChartSelectors', () => {

describe('start date and end date set and user clicks on the date', () => {
it('clears the params', async () => {
const { user } = setup()
const { user } = setup({})
const updateParams = jest.fn()
const testDate = new Date('2022-03-31T00:00:00.000Z')

Expand Down Expand Up @@ -241,7 +251,7 @@ describe('ChartSelectors', () => {

describe('interacting with the multi select', () => {
it('displays list of repos when opened', async () => {
const { user } = setup()
const { user } = setup({})
render(
<ChartSelectors
active={true}
Expand All @@ -267,7 +277,7 @@ describe('ChartSelectors', () => {

describe('when item clicked', () => {
it('updates button value', async () => {
const { user } = setup()
const { user } = setup({})
render(
<ChartSelectors
active={true}
Expand All @@ -292,7 +302,7 @@ describe('ChartSelectors', () => {
})

it('updates url params', async () => {
const { user } = setup()
const { user } = setup({})
const updateParams = jest.fn()
render(
<ChartSelectors
Expand Down Expand Up @@ -321,7 +331,7 @@ describe('ChartSelectors', () => {

describe('when searching for a repo', () => {
it('displays the searchbox', async () => {
const { user } = setup()
const { user } = setup({})
render(
<ChartSelectors
active={true}
Expand All @@ -343,7 +353,7 @@ describe('ChartSelectors', () => {
})

it('updates the textbox value when typing', async () => {
const { user } = setup()
const { user } = setup({})
render(
<ChartSelectors
active={true}
Expand Down Expand Up @@ -386,7 +396,7 @@ describe('ChartSelectors', () => {
describe('when onLoadMore is triggered', () => {
describe('when there is a next page', () => {
it('calls fetchNextPage', async () => {
const { user, fetchNextPage } = setup()
const { user, fetchNextPage } = setup({ hasNextPage: true })
useIntersection.mockReturnValue({
isIntersecting: true,
})
Expand Down Expand Up @@ -439,7 +449,7 @@ describe('ChartSelectors', () => {

describe('interacting with clear filters', () => {
it('updates params', async () => {
const { user } = setup()
const { user } = setup({})
const updateParams = jest.fn()
render(
<ChartSelectors
Expand Down Expand Up @@ -471,7 +481,7 @@ describe('ChartSelectors', () => {

describe('owner is on a team plan', () => {
it('renders upgrade cta', async () => {
setup({ hasNextPage: false }, TierNames.TEAM)
setup({ hasNextPage: false, tierValue: TierNames.TEAM })
render(
<ChartSelectors
active={true}
Expand Down
148 changes: 0 additions & 148 deletions src/services/repos/useRepos.js

This file was deleted.

Loading
Loading