Skip to content

Commit bc3d5dd

Browse files
ref: Convert FileEntry to TS (#3772)
1 parent 9a2da1b commit bc3d5dd

File tree

2 files changed

+23
-35
lines changed

2 files changed

+23
-35
lines changed

src/shared/ContentsTable/TableEntries/BaseEntries/FileEntry.test.jsx renamed to src/shared/ContentsTable/TableEntries/BaseEntries/FileEntry.test.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import FileEntry from './FileEntry'
66

77
import { displayTypeParameter } from '../../constants'
88

9-
const wrapper = ({ children }) => (
9+
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
1010
<MemoryRouter initialEntries={['/gh/codecov/test-repo']}>
1111
<Route path="/:provider/:owner/:repo/">{children}</Route>
1212
</MemoryRouter>
@@ -15,15 +15,13 @@ const wrapper = ({ children }) => (
1515
describe('FileEntry', () => {
1616
describe('checking properties on list display', () => {
1717
it('displays the file path', () => {
18-
const runPrefetchMock = vi.fn()
1918
render(
2019
<FileEntry
2120
linkRef="main"
2221
path="dir/file.js"
2322
name="file.js"
2423
urlPath="dir"
2524
displayType={displayTypeParameter.list}
26-
runPrefetch={runPrefetchMock}
2725
/>,
2826
{ wrapper }
2927
)
@@ -34,15 +32,13 @@ describe('FileEntry', () => {
3432

3533
describe('checking properties on tree display', () => {
3634
it('displays the file name', () => {
37-
const runPrefetchMock = vi.fn()
3835
render(
3936
<FileEntry
4037
linkRef="main"
4138
path="dir/file.js"
4239
name="file.js"
4340
urlPath="dir"
4441
displayType={displayTypeParameter.tree}
45-
runPrefetch={runPrefetchMock}
4642
/>,
4743
{ wrapper }
4844
)
@@ -51,15 +47,13 @@ describe('FileEntry', () => {
5147
})
5248

5349
it('does not display the file name', () => {
54-
const runPrefetchMock = vi.fn()
5550
render(
5651
<FileEntry
5752
linkRef="main"
5853
path="dir/file.js"
5954
name="file.js"
6055
urlPath="dir"
6156
displayType={displayTypeParameter.tree}
62-
runPrefetch={runPrefetchMock}
6357
/>,
6458
{ wrapper }
6559
)
@@ -70,15 +64,13 @@ describe('FileEntry', () => {
7064

7165
describe('is displaying a list', () => {
7266
it('displays the file path label', () => {
73-
const runPrefetchMock = vi.fn()
7467
render(
7568
<FileEntry
7669
linkRef="main"
7770
path="dir/file.js"
7871
name="file.js"
7972
urlPath="dir"
8073
displayType={displayTypeParameter.list}
81-
runPrefetch={runPrefetchMock}
8274
/>,
8375
{ wrapper }
8476
)
@@ -110,7 +102,6 @@ describe('FileEntry', () => {
110102
})
111103

112104
describe('passed pageName commit props', () => {
113-
const runPrefetchMock = vi.fn()
114105
it('sets the correct href', () => {
115106
render(
116107
<FileEntry
@@ -119,7 +110,6 @@ describe('FileEntry', () => {
119110
urlPath="dir"
120111
commitSha="coolCommitSha"
121112
displayType={displayTypeParameter.tree}
122-
runPrefetch={runPrefetchMock}
123113
pageName="commitFileDiff"
124114
/>,
125115
{ wrapper }
@@ -135,15 +125,13 @@ describe('FileEntry', () => {
135125

136126
describe('passed queryParams prop', () => {
137127
it('sets the correct href', () => {
138-
const runPrefetchMock = vi.fn()
139128
render(
140129
<FileEntry
141130
linkRef="main"
142131
path="dir/file.js"
143132
name="file.js"
144133
urlPath="dir"
145134
displayType={displayTypeParameter.list}
146-
runPrefetch={runPrefetchMock}
147135
queryParams={{ flags: ['flag-1'] }}
148136
/>,
149137
{ wrapper }
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import PropTypes from 'prop-types'
2-
31
import A from 'ui/A'
42
import Icon from 'ui/Icon'
53

64
import { displayTypeParameter } from '../../constants'
75

8-
const FileHeader = ({ displayAsList, path, name }) => {
6+
interface FileHeaderProps {
7+
displayAsList: boolean
8+
path: string
9+
name: string
10+
}
11+
12+
const FileHeader = ({ displayAsList, path, name }: FileHeaderProps) => {
913
return (
1014
<div className="flex items-center gap-1 break-all">
1115
{!displayAsList && <Icon name="document" size="md" />}
@@ -14,23 +18,17 @@ const FileHeader = ({ displayAsList, path, name }) => {
1418
)
1519
}
1620

17-
FileHeader.propTypes = {
18-
path: PropTypes.string.isRequired,
19-
name: PropTypes.string.isRequired,
20-
displayAsList: PropTypes.bool.isRequired,
21-
}
22-
2321
function FileEntry({
2422
linkRef,
2523
path,
2624
name,
2725
urlPath,
2826
displayType,
29-
runPrefetch,
27+
runPrefetch = () => Promise.resolve(),
3028
pageName = 'fileViewer',
3129
commitSha,
32-
queryParams,
33-
}) {
30+
queryParams = {},
31+
}: FileEntryProps) {
3432
const displayAsList = displayType === displayTypeParameter.list
3533
return (
3634
<div
@@ -47,23 +45,25 @@ function FileEntry({
4745
queryParams,
4846
},
4947
}}
48+
hook="expand-file-entry"
49+
isExternal={false}
5050
>
5151
<FileHeader displayAsList={displayAsList} path={path} name={name} />
5252
</A>
5353
</div>
5454
)
5555
}
5656

57-
FileEntry.propTypes = {
58-
linkRef: PropTypes.string,
59-
path: PropTypes.string,
60-
name: PropTypes.string.isRequired,
61-
displayType: PropTypes.oneOf(Object.values(displayTypeParameter)),
62-
urlPath: PropTypes.string.isRequired,
63-
runPrefetch: PropTypes.func,
64-
pageName: PropTypes.string,
65-
commitSha: PropTypes.string,
66-
queryParams: PropTypes.object,
57+
interface FileEntryProps {
58+
linkRef?: string
59+
path: string
60+
name: string
61+
displayType?: (typeof displayTypeParameter)[keyof typeof displayTypeParameter]
62+
urlPath: string
63+
runPrefetch?: () => Promise<void>
64+
pageName?: string
65+
commitSha?: string
66+
queryParams?: any
6767
}
6868

6969
export default FileEntry

0 commit comments

Comments
 (0)