Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidebar Navigation for Reference Pages #50

Merged
merged 15 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import Header from './Header';
import './styles.scss';

const pages = [
{ displayName: 'Collect Data', url: 'collect-data' },
{ displayName: 'Explore Data', url: 'explore-data' },
{ displayName: 'Build Apps', url: 'build-apps' },
{ displayName: 'Automate Workflows', url: 'automate-workflows' },
{ displayName: 'Developer Docs', url: 'docs' },
{ displayName: 'Collect Data', url: '/collect-data' },
{ displayName: 'Explore Data', url: '/explore-data' },
{ displayName: 'Build Apps', url: '/build-apps' },
{ displayName: 'Automate Workflows', url: '/automate-workflows' },
{ displayName: 'Developer Docs', url: '/docs' },
];

const Layout = ({ children }) => (
Expand Down
10 changes: 7 additions & 3 deletions src/components/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import './Sidebar.scss';
// recursively create navigation
const renderNav = (page, index) => (
<li key={index}>
<Link to={page.url} className={cx({ 'is-active': page.active })}>
{page.displayName}
</Link>
{page.url ? (
<Link to={page.url} className={cx({ 'is-active': page.active })}>
{page.displayName}
</Link>
) : (
<div>{page.displayName}</div>
)}
{page.children && <ul>{page.children.map(renderNav)}</ul>}
</li>
);
Expand Down
21 changes: 21 additions & 0 deletions src/data/sidenav.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"displayName": "Guides",
"url": "/guides"
},
{
"displayName": "Foo",
"children": [
{
"displayName": "Baz",
"url": "/foo/baz",
"children": []
},
{
"displayName": "Bar",
"url": "/foo/bar",
"children": []
}
]
}
]
10 changes: 10 additions & 0 deletions src/markdown-pages/foo-bar-baz.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
path: '/foo/baz'
duration: '0 min'
title: 'Baz'
template: 'GuideTemplate'
---

## This is the Baz page within Foo

Page added to test the sidebar navigation.
10 changes: 10 additions & 0 deletions src/markdown-pages/foo-bar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
path: '/foo/bar'
duration: '0 min'
title: 'Bar'
template: 'GuideTemplate'
---

## This is the Bar page within Foo

Page added to test the sidebar navigation.
10 changes: 10 additions & 0 deletions src/markdown-pages/guide-index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
path: '/guides'
duration: '0 min'
title: 'Guides'
template: 'GuideTemplate'
---

## This is the top-level guide page

Page added to test the sidebar navigation.
52 changes: 2 additions & 50 deletions src/pages/reference.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,13 @@
import React, { useState } from 'react';

import Container from '../components/Container';
import Layout from '../components/Layout';
import Sidebar from '../components/Sidebar';

import pages from '../data/sidenav.json';

// TODO: move this js file to same directory and update import
import '../templates/Reference.scss';

// TODO: pull this in from Gatsby
const pages = [
{ displayName: 'Overview', url: '' },
{
displayName: 'CLI',
url: '',
children: [
{ displayName: 'newrelic', url: '' },
{ displayName: 'nr1', url: '' },
],
},
{ displayName: 'GraphQL', url: '' },
{
displayName: 'Applications',
url: '',
children: [
{ displayName: 'Component Library', url: '', active: true },
{ displayName: 'File structure', url: '' },
],
},
{
displayName: 'Data Collectors',
url: '',
children: [
{ displayName: 'Custom Attributes', url: '' },
{ displayName: 'Custom Events', url: '' },
{ displayName: 'Open Telemetry', url: '' },
{ displayName: 'Telemetry SDK', url: '' },
],
},
{
displayName: 'Automation',
url: '',
children: [
{ displayName: 'Cloud Formation Provider', url: '' },
{ displayName: 'Terraform Provider', url: '' },
{
displayName: 'Agent Deploy',
url: '',
children: [
{ displayName: 'Ansible', url: '' },
{ displayName: 'Chef', url: '' },
{ displayName: 'Puppet', url: '' },
],
},
],
},
];

const Reference = () => {
const [isOpen, setIsOpen] = useState(false);

Expand Down
2 changes: 1 addition & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
// it is not very performant.
export const link = PropTypes.shape({
displayName: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
url: PropTypes.string,
active: PropTypes.bool,
children: PropTypes.array,
});