Skip to content

Commit 2d55abc

Browse files
authored
Merge pull request #50 from newrelic/zstickles/sidebar-nav
Sidebar Navigation for Reference Pages
2 parents 957fab7 + 969f9d2 commit 2d55abc

File tree

8 files changed

+66
-59
lines changed

8 files changed

+66
-59
lines changed

src/components/Layout.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import Header from './Header';
66
import './styles.scss';
77

88
const pages = [
9-
{ displayName: 'Collect Data', url: 'collect-data' },
10-
{ displayName: 'Explore Data', url: 'explore-data' },
11-
{ displayName: 'Build Apps', url: 'build-apps' },
12-
{ displayName: 'Automate Workflows', url: 'automate-workflows' },
13-
{ displayName: 'Developer Docs', url: 'docs' },
9+
{ displayName: 'Collect Data', url: '/collect-data' },
10+
{ displayName: 'Explore Data', url: '/explore-data' },
11+
{ displayName: 'Build Apps', url: '/build-apps' },
12+
{ displayName: 'Automate Workflows', url: '/automate-workflows' },
13+
{ displayName: 'Developer Docs', url: '/docs' },
1414
];
1515

1616
const Layout = ({ children }) => (

src/components/Sidebar.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ import './Sidebar.scss';
99
// recursively create navigation
1010
const renderNav = (page, index) => (
1111
<li key={index}>
12-
<Link to={page.url} className={cx({ 'is-active': page.active })}>
13-
{page.displayName}
14-
</Link>
12+
{page.url ? (
13+
<Link to={page.url} className={cx({ 'is-active': page.active })}>
14+
{page.displayName}
15+
</Link>
16+
) : (
17+
<div>{page.displayName}</div>
18+
)}
1519
{page.children && <ul>{page.children.map(renderNav)}</ul>}
1620
</li>
1721
);

src/data/sidenav.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[
2+
{
3+
"displayName": "Guides",
4+
"url": "/guides"
5+
},
6+
{
7+
"displayName": "Foo",
8+
"children": [
9+
{
10+
"displayName": "Baz",
11+
"url": "/foo/baz",
12+
"children": []
13+
},
14+
{
15+
"displayName": "Bar",
16+
"url": "/foo/bar",
17+
"children": []
18+
}
19+
]
20+
}
21+
]

src/markdown-pages/foo-bar-baz.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
path: '/foo/baz'
3+
duration: '0 min'
4+
title: 'Baz'
5+
template: 'GuideTemplate'
6+
---
7+
8+
## This is the Baz page within Foo
9+
10+
Page added to test the sidebar navigation.

src/markdown-pages/foo-bar.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
path: '/foo/bar'
3+
duration: '0 min'
4+
title: 'Bar'
5+
template: 'GuideTemplate'
6+
---
7+
8+
## This is the Bar page within Foo
9+
10+
Page added to test the sidebar navigation.

src/markdown-pages/guide-index.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
path: '/guides'
3+
duration: '0 min'
4+
title: 'Guides'
5+
template: 'GuideTemplate'
6+
---
7+
8+
## This is the top-level guide page
9+
10+
Page added to test the sidebar navigation.

src/pages/reference.js

+2-50
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,13 @@
11
import React, { useState } from 'react';
2-
32
import Container from '../components/Container';
43
import Layout from '../components/Layout';
54
import Sidebar from '../components/Sidebar';
65

6+
import pages from '../data/sidenav.json';
7+
78
// TODO: move this js file to same directory and update import
89
import '../templates/Reference.scss';
910

10-
// TODO: pull this in from Gatsby
11-
const pages = [
12-
{ displayName: 'Overview', url: '' },
13-
{
14-
displayName: 'CLI',
15-
url: '',
16-
children: [
17-
{ displayName: 'newrelic', url: '' },
18-
{ displayName: 'nr1', url: '' },
19-
],
20-
},
21-
{ displayName: 'GraphQL', url: '' },
22-
{
23-
displayName: 'Applications',
24-
url: '',
25-
children: [
26-
{ displayName: 'Component Library', url: '', active: true },
27-
{ displayName: 'File structure', url: '' },
28-
],
29-
},
30-
{
31-
displayName: 'Data Collectors',
32-
url: '',
33-
children: [
34-
{ displayName: 'Custom Attributes', url: '' },
35-
{ displayName: 'Custom Events', url: '' },
36-
{ displayName: 'Open Telemetry', url: '' },
37-
{ displayName: 'Telemetry SDK', url: '' },
38-
],
39-
},
40-
{
41-
displayName: 'Automation',
42-
url: '',
43-
children: [
44-
{ displayName: 'Cloud Formation Provider', url: '' },
45-
{ displayName: 'Terraform Provider', url: '' },
46-
{
47-
displayName: 'Agent Deploy',
48-
url: '',
49-
children: [
50-
{ displayName: 'Ansible', url: '' },
51-
{ displayName: 'Chef', url: '' },
52-
{ displayName: 'Puppet', url: '' },
53-
],
54-
},
55-
],
56-
},
57-
];
58-
5911
const Reference = () => {
6012
const [isOpen, setIsOpen] = useState(false);
6113

src/types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
44
// it is not very performant.
55
export const link = PropTypes.shape({
66
displayName: PropTypes.string.isRequired,
7-
url: PropTypes.string.isRequired,
7+
url: PropTypes.string,
88
active: PropTypes.bool,
99
children: PropTypes.array,
1010
});

0 commit comments

Comments
 (0)