Skip to content

Commit

Permalink
chore: abstracted commonly used type to types file
Browse files Browse the repository at this point in the history
  • Loading branch information
zstix committed Apr 24, 2020
1 parent 566475c commit dd98558
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import './Header.scss';

import { Link, graphql, useStaticQuery } from 'gatsby';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Link, graphql, useStaticQuery } from 'gatsby';
import cx from 'classnames';

import { link } from '../types';
import Container from './Container';
import ExternalLink from './ExternalLink';
import HamburgerMenu from './HamburgerMenu';
import PropTypes from 'prop-types';
import cx from 'classnames';
import './Header.scss';

const Header = ({ pages }) => {
const [menuOpen, setMenuOpen] = useState(false);
Expand Down Expand Up @@ -79,7 +79,7 @@ const Header = ({ pages }) => {
<ul>
{pages.map((page, i) => (
<li key={i}>
<Link to={page.path}>{page.displayName}</Link>
<Link to={page.url}>{page.displayName}</Link>
</li>
))}
</ul>
Expand All @@ -105,22 +105,16 @@ const Header = ({ pages }) => {
};

Header.propTypes = {
pages: PropTypes.arrayOf(
PropTypes.shape({
displayName: PropTypes.string.isRequired,
path: PropTypes.string.isRequired,
active: PropTypes.bool,
})
),
pages: PropTypes.arrayOf(link),
};

Header.defaultProps = {
pages: [
{ displayName: 'Collect Data', path: '' },
{ displayName: 'Explore Data', path: 'explore-data' },
{ displayName: 'Build Apps', path: '' },
{ displayName: 'Automate New Relic', path: '' },
{ displayName: 'Reference Docs', path: '' },
{ displayName: 'Collect Data', url: '' },
{ displayName: 'Explore Data', url: 'explore-data' },
{ displayName: 'Build Apps', url: '' },
{ displayName: 'Automate New Relic', url: '' },
{ displayName: 'Reference Docs', url: '' },
],
};

Expand Down
10 changes: 10 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import PropTypes from 'prop-types';

// NOTE: while creating a recursive data structure is feasible,
// it is not very performant.
export const link = PropTypes.shape({
displayName: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
active: PropTypes.bool,
children: PropTypes.array,
});

0 comments on commit dd98558

Please sign in to comment.