diff --git a/src/pages/CommitDetailPage/subRoute/CommitDetailFileExplorer/CommitDetailFileExplorer.jsx b/src/pages/CommitDetailPage/subRoute/CommitDetailFileExplorer/CommitDetailFileExplorer.jsx
index 0c7370c45f..652e9ea1a9 100644
--- a/src/pages/CommitDetailPage/subRoute/CommitDetailFileExplorer/CommitDetailFileExplorer.jsx
+++ b/src/pages/CommitDetailPage/subRoute/CommitDetailFileExplorer/CommitDetailFileExplorer.jsx
@@ -10,6 +10,8 @@ import Spinner from 'ui/Spinner'
import { useRepoCommitContentsTable } from './hooks'
+import ComponentsSelector from '../ComponentsSelector'
+
const Loader = () => (
@@ -36,12 +38,15 @@ function CommitDetailFileExplorer() {
- updateParams({ search })}
- />
+
+
+ updateParams({ search })}
+ />
+
() => 'Components Selector')
+
const queryClient = new QueryClient({
defaultOptions: {
queries: {
@@ -181,6 +183,13 @@ describe('CommitDetailFileExplorer', () => {
const coverage = await screen.findByText('Coverage %')
expect(coverage).toBeInTheDocument()
})
+
+ it('renders components selector', async () => {
+ render(, { wrapper: wrapper() })
+
+ const table = await screen.findByText('Components Selector')
+ expect(table).toBeInTheDocument()
+ })
})
describe('table is displaying file tree', () => {
diff --git a/src/pages/CommitDetailPage/subRoute/CommitDetailFileExplorer/hooks/useRepoCommitContentsTable.js b/src/pages/CommitDetailPage/subRoute/CommitDetailFileExplorer/hooks/useRepoCommitContentsTable.js
index 4cbe0f42a1..9a7143206e 100644
--- a/src/pages/CommitDetailPage/subRoute/CommitDetailFileExplorer/hooks/useRepoCommitContentsTable.js
+++ b/src/pages/CommitDetailPage/subRoute/CommitDetailFileExplorer/hooks/useRepoCommitContentsTable.js
@@ -153,13 +153,19 @@ const sortingParameter = Object.freeze({
const getQueryFilters = ({ params, sortBy }) => {
let flags = {}
+ let components = {}
if (params?.flags) {
flags = { flags: params?.flags }
}
+ if (params?.components) {
+ components = { components: params?.components }
+ }
+
return {
...(params?.search && { searchValue: params.search }),
...flags,
+ ...components,
...(params?.displayType && {
displayType: displayTypeParameter[params?.displayType],
}),
diff --git a/src/pages/CommitDetailPage/subRoute/CommitDetailFileExplorer/hooks/useRepoCommitContentsTable.spec.js b/src/pages/CommitDetailPage/subRoute/CommitDetailFileExplorer/hooks/useRepoCommitContentsTable.spec.js
index 3114ced238..f91c591c89 100644
--- a/src/pages/CommitDetailPage/subRoute/CommitDetailFileExplorer/hooks/useRepoCommitContentsTable.spec.js
+++ b/src/pages/CommitDetailPage/subRoute/CommitDetailFileExplorer/hooks/useRepoCommitContentsTable.spec.js
@@ -286,6 +286,42 @@ describe('useRepoCommitContentsTable', () => {
})
})
+ describe('when there is a flags and components param', () => {
+ beforeEach(() => {
+ useLocationParams.mockReturnValue({
+ params: { flags: ['flag-1'], components: ['component-1'] },
+ })
+ })
+
+ it('makes a gql request with the flags and components value', async () => {
+ setup({})
+
+ const { result } = renderHook(() => useRepoCommitContentsTable(), {
+ wrapper: wrapper(),
+ })
+
+ await waitFor(() => result.current.isLoading)
+ await waitFor(() => !result.current.isLoading)
+
+ expect(calledCommitContents).toHaveBeenCalled()
+ expect(calledCommitContents).toHaveBeenCalledWith({
+ commit: 'sha256',
+ filters: {
+ flags: ['flag-1'],
+ components: ['component-1'],
+
+ ordering: {
+ direction: 'ASC',
+ parameter: 'NAME',
+ },
+ },
+ name: 'test-org',
+ repo: 'test-repo',
+ path: '',
+ })
+ })
+ })
+
describe('when handleSort is triggered', () => {
beforeEach(() => {
useLocationParams.mockReturnValue({
diff --git a/src/services/pathContents/commit/file/usePrefetchCommitFileEntry.spec.tsx b/src/services/pathContents/commit/file/usePrefetchCommitFileEntry.spec.tsx
index 2f2447a96b..dd8ae5c8ce 100644
--- a/src/services/pathContents/commit/file/usePrefetchCommitFileEntry.spec.tsx
+++ b/src/services/pathContents/commit/file/usePrefetchCommitFileEntry.spec.tsx
@@ -260,6 +260,34 @@ describe('usePrefetchCommitFileEntry', () => {
})
})
+ describe('flags and components arg is passed', () => {
+ it('fetches with passed variables', async () => {
+ const { mockVars } = setup({})
+ const { result } = renderHook(
+ () =>
+ usePrefetchCommitFileEntry({
+ commitSha: 'f00162848a3cebc0728d915763c2fd9e92132408',
+ path: 'src/file.js',
+ flags: ['flag-1', 'flag-2'],
+ components: ['c-1', 'c-2'],
+ }),
+ { wrapper }
+ )
+
+ await result.current.runPrefetch()
+
+ await waitFor(() => expect(mockVars).toBeCalled())
+ await waitFor(() =>
+ expect(mockVars).toHaveBeenCalledWith(
+ expect.objectContaining({
+ flags: ['flag-1', 'flag-2'],
+ components: ['c-1', 'c-2'],
+ })
+ )
+ )
+ })
+ })
+
describe('returns NotFoundError __typename', () => {
beforeEach(() => {
jest.spyOn(console, 'error')
diff --git a/src/services/pathContents/commit/file/usePrefetchCommitFileEntry.tsx b/src/services/pathContents/commit/file/usePrefetchCommitFileEntry.tsx
index 68131dfcb0..33432ba23b 100644
--- a/src/services/pathContents/commit/file/usePrefetchCommitFileEntry.tsx
+++ b/src/services/pathContents/commit/file/usePrefetchCommitFileEntry.tsx
@@ -17,6 +17,7 @@ interface UsePrefetchCommitFileEntryArgs {
commitSha: string
path: string
flags?: Array
+ components?: Array
options?: QueryOptions
}
@@ -24,6 +25,7 @@ export function usePrefetchCommitFileEntry({
commitSha,
path,
flags = [],
+ components = [],
options = {},
}: UsePrefetchCommitFileEntryArgs) {
const { provider, owner, repo } = useParams()
@@ -31,7 +33,16 @@ export function usePrefetchCommitFileEntry({
const runPrefetch = async () => {
await queryClient.prefetchQuery({
- queryKey: ['commit', provider, owner, repo, commitSha, path, flags],
+ queryKey: [
+ 'commit',
+ provider,
+ owner,
+ repo,
+ commitSha,
+ path,
+ flags,
+ components,
+ ],
queryFn: ({ signal }) => {
return Api.graphql({
provider,
@@ -44,6 +55,7 @@ export function usePrefetchCommitFileEntry({
ref: commitSha,
path,
flags,
+ components,
},
}).then((res) => {
const parsedRes = RequestSchema.safeParse(res?.data)
diff --git a/src/shared/ContentsTable/TableEntries/CommitEntries/CommitDirEntry.jsx b/src/shared/ContentsTable/TableEntries/CommitEntries/CommitDirEntry.jsx
index b9b315bf59..d9917fe5f4 100644
--- a/src/shared/ContentsTable/TableEntries/CommitEntries/CommitDirEntry.jsx
+++ b/src/shared/ContentsTable/TableEntries/CommitEntries/CommitDirEntry.jsx
@@ -6,6 +6,7 @@ import DirEntry from '../BaseEntries/DirEntry'
function CommitDirEntry({ commitSha, urlPath, name, filters }) {
const flags = filters?.flags?.length > 0 ? filters?.flags : []
+ const components = filters?.components?.length > 0 ? filters?.components : []
const { runPrefetch } = usePrefetchCommitDirEntry({
commit: commitSha,
@@ -20,7 +21,7 @@ function CommitDirEntry({ commitSha, urlPath, name, filters }) {
runPrefetch={runPrefetch}
pageName="commitTreeView"
commitSha={commitSha}
- queryParams={{ flags }}
+ queryParams={{ flags, components }}
/>
)
}
@@ -36,6 +37,7 @@ CommitDirEntry.propTypes = {
}),
searchValue: PropTypes.any,
flags: PropTypes.arrayOf(PropTypes.string),
+ components: PropTypes.arrayOf(PropTypes.string),
}),
}
diff --git a/src/shared/ContentsTable/TableEntries/CommitEntries/CommitDirEntry.spec.jsx b/src/shared/ContentsTable/TableEntries/CommitEntries/CommitDirEntry.spec.jsx
index c714e7797d..70b0594ca5 100644
--- a/src/shared/ContentsTable/TableEntries/CommitEntries/CommitDirEntry.spec.jsx
+++ b/src/shared/ContentsTable/TableEntries/CommitEntries/CommitDirEntry.spec.jsx
@@ -115,7 +115,7 @@ describe('CommitDirEntry', () => {
commitSha="1234"
name="dir"
urlPath="path/to/directory"
- filters={{ flags: ['flag-1'] }}
+ filters={{ flags: ['flag-1'], components: ['component-1'] }}
/>,
{ wrapper }
)
@@ -124,7 +124,7 @@ describe('CommitDirEntry', () => {
expect(a).toHaveAttribute(
'href',
`/gh/codecov/test-repo/commit/1234/tree/path/to/directory/dir${qs.stringify(
- { flags: ['flag-1'] },
+ { flags: ['flag-1'], components: ['component-1'] },
{ addQueryPrefix: true }
)}`
)
diff --git a/src/shared/ContentsTable/TableEntries/CommitEntries/CommitFileEntry.jsx b/src/shared/ContentsTable/TableEntries/CommitEntries/CommitFileEntry.jsx
index 760df035bf..7a6872f788 100644
--- a/src/shared/ContentsTable/TableEntries/CommitEntries/CommitFileEntry.jsx
+++ b/src/shared/ContentsTable/TableEntries/CommitEntries/CommitFileEntry.jsx
@@ -15,11 +15,13 @@ function CommitFileEntry({
filters,
}) {
const flags = filters?.flags?.length > 0 ? filters?.flags : []
+ const components = filters?.components?.length > 0 ? filters?.components : []
const { runPrefetch } = usePrefetchCommitFileEntry({
path,
commitSha,
flags,
+ components,
})
return (
@@ -32,7 +34,7 @@ function CommitFileEntry({
path={path}
runPrefetch={runPrefetch}
pageName="commitFileDiff"
- queryParams={{ flags }}
+ queryParams={{ flags, components }}
/>
)
}
@@ -46,6 +48,7 @@ CommitFileEntry.propTypes = {
path: PropTypes.string,
filters: PropTypes.shape({
flags: PropTypes.arrayOf(PropTypes.string),
+ components: PropTypes.arrayOf(PropTypes.string),
}),
}
diff --git a/src/shared/ContentsTable/TableEntries/CommitEntries/CommitFileEntry.spec.jsx b/src/shared/ContentsTable/TableEntries/CommitEntries/CommitFileEntry.spec.jsx
index b463bce37a..eb1d52a839 100644
--- a/src/shared/ContentsTable/TableEntries/CommitEntries/CommitFileEntry.spec.jsx
+++ b/src/shared/ContentsTable/TableEntries/CommitEntries/CommitFileEntry.spec.jsx
@@ -128,6 +128,31 @@ describe('CommitFileEntry', () => {
)
})
})
+
+ describe('filters with flags and components are passed', () => {
+ it('sets the correct query params', () => {
+ setup()
+ render(
+ ,
+ { wrapper }
+ )
+
+ const path = screen.getByRole('link', { name: 'dir/file.js' })
+ expect(path).toBeInTheDocument()
+ expect(path).toHaveAttribute(
+ 'href',
+ '/gh/codecov/test-repo/commit/1234/blob/dir/file.js?flags%5B0%5D=flag-1&components%5B0%5D=component-test'
+ )
+ })
+ })
})
describe('checking properties on tree display', () => {