diff --git a/theme/gatsby-node.js b/theme/gatsby-node.js index 0e7f743a4e6..5cdf16a10ab 100644 --- a/theme/gatsby-node.js +++ b/theme/gatsby-node.js @@ -62,7 +62,7 @@ exports.createPages = async ({graphql, actions}, {repo, showContributors}) => { const relativePath = path.relative(rootAbsolutePath, fileAbsolutePath) const editUrl = getEditUrl(repo, relativePath, frontmatter) - const contributors = showContributors ? await fetchContributors(repo, relativePath, frontmatter) : [] + const contributors = showContributors ? await fetchContributors(repo, relativePath, frontmatter) : {} // Fix some old CLI pages which have mismatched headings at the top level. // All top level headings should be the same level. diff --git a/theme/src/components/__tests__/contributors.test.js b/theme/src/components/__tests__/contributors.test.js index 7465ca93cb9..725fadc771f 100644 --- a/theme/src/components/__tests__/contributors.test.js +++ b/theme/src/components/__tests__/contributors.test.js @@ -5,13 +5,11 @@ import Contributors from '../contributors' test('renders contributors', () => { const {queryByText} = render( , ) @@ -23,16 +21,8 @@ test('renders contributors', () => { }) test('does not render "last edited by" if latest contributor does not have a latest commit', () => { - const {queryByText} = render() + const {queryByText} = render() expect(queryByText(/1 contributor/)).toBeInTheDocument() expect(queryByText(/Last edited by/)).toBeNull() }) - -// The `Contributors` component is unlikely to be passed an empty array -// but it should be able to handle an empty array gracefully just in case. -test('handles no contributors', () => { - const {queryByText} = render() - - expect(queryByText(/0 contributors/)).toBeInTheDocument() -}) diff --git a/theme/src/components/__tests__/page-footer.test.js b/theme/src/components/__tests__/page-footer.test.js index f2ee21d839e..b070ba69825 100644 --- a/theme/src/components/__tests__/page-footer.test.js +++ b/theme/src/components/__tests__/page-footer.test.js @@ -3,7 +3,7 @@ import React from 'react' import PageFooter from '../page-footer' test('renders correctly when editUrl and contributors are defined', () => { - const {queryByText} = render() + const {queryByText} = render() expect(queryByText(/Edit this page on GitHub/)).toBeInTheDocument() expect(queryByText(/contributor/)).toBeInTheDocument() @@ -24,14 +24,20 @@ test('renders correctly when editUrl is defined but contributors is undefined', }) test('renders correctly when contributors is defined but editUrl is undefined', () => { - const {queryByText} = render() + const {queryByText} = render() expect(queryByText(/Edit this page on GitHub/)).toBeNull() expect(queryByText(/contributor/)).toBeInTheDocument() }) test('does not render contributors if contributors is an empty array', () => { - const {queryByText} = render() + const {queryByText} = render() + + expect(queryByText(/contributor/)).toBeNull() +}) + +test('does not render contributors if contributors is empty object', () => { + const {queryByText} = render() expect(queryByText(/contributor/)).toBeNull() }) diff --git a/theme/src/components/contributors.js b/theme/src/components/contributors.js index d70442a11ef..689e1d10591 100644 --- a/theme/src/components/contributors.js +++ b/theme/src/components/contributors.js @@ -19,8 +19,7 @@ const months = [ ] const format = d => `${months[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}` -function Contributors({contributors}) { - const {logins = [], latestCommit} = contributors +function Contributors({logins, latestCommit}) { return (
diff --git a/theme/src/components/details.js b/theme/src/components/details.js index 7ab49e26016..5cf379868e3 100644 --- a/theme/src/components/details.js +++ b/theme/src/components/details.js @@ -29,7 +29,7 @@ function getRenderer(children) { return typeof children === 'function' ? children : () => children } -function Details({children, overlay, render = getRenderer(children), ...rest}) { +function Details({children, overlay = false, render = getRenderer(children), ...rest}) { const [open, setOpen] = React.useState(Boolean(rest.open)) function toggle(event) { @@ -62,8 +62,4 @@ function Details({children, overlay, render = getRenderer(children), ...rest}) { ) } -Details.defaultProps = { - overlay: false, -} - export default Details diff --git a/theme/src/components/page-footer.js b/theme/src/components/page-footer.js index 612bbb5ca70..b6c5964a5cc 100644 --- a/theme/src/components/page-footer.js +++ b/theme/src/components/page-footer.js @@ -3,8 +3,9 @@ import {PencilIcon} from '@primer/octicons-react' import React from 'react' import Contributors from './contributors' -function PageFooter({editUrl, contributors}) { - return editUrl || contributors.length > 0 ? ( +function PageFooter({editUrl, contributors = {}}) { + const {logins = [], latestCommit} = contributors + return editUrl || logins.length ? ( {editUrl != null ? ( @@ -13,15 +14,10 @@ function PageFooter({editUrl, contributors}) { Edit this page on GitHub ) : null} - - {contributors.length ? : null} + {logins.length ? : null} ) : null } -PageFooter.defaultProps = { - contributors: [], -} - export default PageFooter diff --git a/theme/src/components/table-of-contents.js b/theme/src/components/table-of-contents.js index 851d364fb5e..0ae81628071 100644 --- a/theme/src/components/table-of-contents.js +++ b/theme/src/components/table-of-contents.js @@ -1,7 +1,7 @@ import {Box, Link} from '@primer/components' import React from 'react' -function TableOfContents({items, depth, labelId}) { +function TableOfContents({items, depth = 0, labelId}) { return (