Separate contributors props into logins+latestCommit (#758)
Luke Karrys committed
Oct 13, 2023 at 23:25 UTC
6baca8be25cf61be87b75afc318a3d976c16e6b7
7 files changed
+23
-40
theme/gatsby-node.js
+1
-1
@@ -62,7 +62,7 @@ exports.createPages = async ({graphql, actions}, {repo, showContributors}) => {
62
const relativePath = path.relative(rootAbsolutePath, fileAbsolutePath)
63
const editUrl = getEditUrl(repo, relativePath, frontmatter)
64
65
- const contributors = showContributors ? await fetchContributors(repo, relativePath, frontmatter) : []
65
+ const contributors = showContributors ? await fetchContributors(repo, relativePath, frontmatter) : {}
66
67
// Fix some old CLI pages which have mismatched headings at the top level.
68
// All top level headings should be the same level.
theme/src/components/__tests__/contributors.test.js
+6
-16
@@ -5,13 +5,11 @@ import Contributors from '../contributors'
5
test('renders contributors', () => {
6
const {queryByText} = render(
7
<Contributors
8
- contributors={{
9
- logins: ['colebemis', 'emplums'],
10
- latestCommit: {
11
- login: 'colebemis',
12
- url: '#',
13
- date: '2019-08-15T23:40:19Z',
14
- },
8
+ logins={['colebemis', 'emplums']}
9
+ latestCommit={{
10
+ login: 'colebemis',
11
+ url: '#',
12
+ date: '2019-08-15T23:40:19Z',
13
}}
14
/>,
15
)
@@ -23,16 +21,8 @@ test('renders contributors', () => {
21
})
22
23
test('does not render "last edited by" if latest contributor does not have a latest commit', () => {
26
- const {queryByText} = render(<Contributors contributors={{logins: ['ashygee']}} />)
24
+ const {queryByText} = render(<Contributors logins={['ashygee']} />)
25
26
expect(queryByText(/1 contributor/)).toBeInTheDocument()
27
expect(queryByText(/Last edited by/)).toBeNull()
28
})
31
-
32
-// The `Contributors` component is unlikely to be passed an empty array
33
-// but it should be able to handle an empty array gracefully just in case.
34
-test('handles no contributors', () => {
35
- const {queryByText} = render(<Contributors contributors={[]} />)
36
-
37
- expect(queryByText(/0 contributors/)).toBeInTheDocument()
38
-})
theme/src/components/__tests__/page-footer.test.js
+9
-3
@@ -3,7 +3,7 @@ import React from 'react'
3
import PageFooter from '../page-footer'
4
5
test('renders correctly when editUrl and contributors are defined', () => {
6
- const {queryByText} = render(<PageFooter editUrl="#" contributors={[{login: 'broccolini'}]} />)
6
+ const {queryByText} = render(<PageFooter editUrl="#" contributors={{logins: ['broccolini']}} />)
7
8
expect(queryByText(/Edit this page on GitHub/)).toBeInTheDocument()
9
expect(queryByText(/contributor/)).toBeInTheDocument()
@@ -24,14 +24,20 @@ test('renders correctly when editUrl is defined but contributors is undefined',
24
})
25
26
test('renders correctly when contributors is defined but editUrl is undefined', () => {
27
- const {queryByText} = render(<PageFooter contributors={[{login: 'broccolini'}]} />)
27
+ const {queryByText} = render(<PageFooter contributors={{logins: ['broccolini']}} />)
28
29
expect(queryByText(/Edit this page on GitHub/)).toBeNull()
30
expect(queryByText(/contributor/)).toBeInTheDocument()
31
})
32
33
test('does not render contributors if contributors is an empty array', () => {
34
- const {queryByText} = render(<PageFooter contributors={[]} />)
34
+ const {queryByText} = render(<PageFooter contributors={{logins: []}} />)
35
+
36
+ expect(queryByText(/contributor/)).toBeNull()
37
+})
38
+
39
+test('does not render contributors if contributors is empty object', () => {
40
+ const {queryByText} = render(<PageFooter contributors={{}} />)
41
42
expect(queryByText(/contributor/)).toBeNull()
43
})
theme/src/components/contributors.js
+1
-2
@@ -19,8 +19,7 @@ const months = [
19
]
20
const format = d => `${months[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`
21
22
-function Contributors({contributors}) {
23
- const {logins = [], latestCommit} = contributors
22
+function Contributors({logins, latestCommit}) {
23
return (
24
<div>
25
<Flex alignItems="center">
theme/src/components/details.js
+1
-5
@@ -29,7 +29,7 @@ function getRenderer(children) {
29
return typeof children === 'function' ? children : () => children
30
}
31
32
-function Details({children, overlay, render = getRenderer(children), ...rest}) {
32
+function Details({children, overlay = false, render = getRenderer(children), ...rest}) {
33
const [open, setOpen] = React.useState(Boolean(rest.open))
34
35
function toggle(event) {
@@ -62,8 +62,4 @@ function Details({children, overlay, render = getRenderer(children), ...rest}) {
62
)
63
}
64
65
-Details.defaultProps = {
66
- overlay: false,
67
-}
68
-
65
export default Details
theme/src/components/page-footer.js
+4
-8
@@ -3,8 +3,9 @@ import {PencilIcon} from '@primer/octicons-react'
3
import React from 'react'
4
import Contributors from './contributors'
5
6
-function PageFooter({editUrl, contributors}) {
7
- return editUrl || contributors.length > 0 ? (
6
+function PageFooter({editUrl, contributors = {}}) {
7
+ const {logins = [], latestCommit} = contributors
8
+ return editUrl || logins.length ? (
9
<BorderBox borderWidth={0} borderTopWidth={1} mt={8} py={5}>
10
<Grid gridGap={4}>
11
{editUrl != null ? (
@@ -13,15 +14,10 @@ function PageFooter({editUrl, contributors}) {
14
Edit this page on GitHub
15
</Link>
16
) : null}
16
-
17
- {contributors.length ? <Contributors contributors={contributors} /> : null}
17
+ {logins.length ? <Contributors logins={logins} latestCommit={latestCommit} /> : null}
18
</Grid>
19
</BorderBox>
20
) : null
21
}
22
23
-PageFooter.defaultProps = {
24
- contributors: [],
25
-}
26
-
23
export default PageFooter
theme/src/components/table-of-contents.js
+1
-5
@@ -1,7 +1,7 @@
1
import {Box, Link} from '@primer/components'
2
import React from 'react'
3
4
-function TableOfContents({items, depth, labelId}) {
4
+function TableOfContents({items, depth = 0, labelId}) {
5
return (
6
<Box
7
key={items}
@@ -24,8 +24,4 @@ function TableOfContents({items, depth, labelId}) {
24
)
25
}
26
27
-TableOfContents.defaultProps = {
28
- depth: 0,
29
-}
30
-
27
export default TableOfContents