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

Fix docs links in sidebar to point to the connected version #752

Merged
merged 1 commit into from
May 4, 2018
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"redux-observable": "^0.16.0",
"rxjs": "^5.4.2",
"save-as": "^0.1.7",
"semver": "^5.5.0",
"styled-components": "^3.2.0",
"stylis": "^3.4.10",
"suber": "^5.0.1",
Expand Down
112 changes: 66 additions & 46 deletions src/browser/modules/Sidebar/Documents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,70 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { connect } from 'preact-redux'
import semver from 'semver'
import { getVersion } from 'shared/modules/dbMeta/dbMetaDuck'
import DocumentItems from './DocumentItems'
import { Drawer, DrawerBody, DrawerHeader } from 'browser-components/drawer'

const staticItems = {
intro: [
{ name: 'Getting started', command: ':play intro', type: 'play' },
{ name: 'Basic graph concepts', command: ':play concepts', type: 'play' },
{ name: 'Writing Cypher queries', command: ':play cypher', type: 'play' }
],
help: [
{ name: 'Help', command: ':help help', type: 'help' },
{ name: 'Cypher syntax', command: ':help cypher', type: 'help' },
{ name: 'Available commands', command: ':help commands', type: 'help' },
{ name: 'Keyboard shortcuts', command: ':help keys', type: 'help' }
],
reference: [
{
name: 'Developer Manual',
command: 'https://neo4j.com/docs/developer-manual/3.2/',
type: 'link'
},
{
name: 'Operations Manual',
command: 'https://neo4j.com/docs/operations-manual/3.2/',
type: 'link'
},
{
name: 'Cypher Refcard',
command: 'https://neo4j.com/docs/cypher-refcard/3.2/',
type: 'link'
},
{
name: 'GraphGists',
command: 'https://neo4j.com/graphgists/',
type: 'link'
},
{
name: 'Developer Site',
command: 'https://www.neo4j.com/developer/',
type: 'link'
},
{
name: 'Knowledge Base',
command: 'https://neo4j.com/developer/kb/',
type: 'link'
}
]
export const formatDocVersion = v => {
if (!semver.valid(v)) return 'current'
return `${semver.major(v)}.${semver.minor(v)}` || 'current'
}

const Documents = ({ items = staticItems }) => {
const intro = [
{ name: 'Getting started', command: ':play intro', type: 'play' },
{ name: 'Basic graph concepts', command: ':play concepts', type: 'play' },
{ name: 'Writing Cypher queries', command: ':play cypher', type: 'play' }
]
const help = [
{ name: 'Help', command: ':help help', type: 'help' },
{ name: 'Cypher syntax', command: ':help cypher', type: 'help' },
{ name: 'Available commands', command: ':help commands', type: 'help' },
{ name: 'Keyboard shortcuts', command: ':help keys', type: 'help' }
]
const getReferences = v => [
{
name: 'Developer Manual',
command: `https://neo4j.com/docs/developer-manual/${v}/`,
type: 'link'
},
{
name: 'Operations Manual',
command: `https://neo4j.com/docs/operations-manual/${v}/`,
type: 'link'
},
{
name: 'Cypher Refcard',
command: `https://neo4j.com/docs/cypher-refcard/${v}/`,
type: 'link'
},
{
name: 'GraphGists',
command: `https://neo4j.com/graphgists/`,
type: 'link'
},
{
name: 'Developer Site',
command: `https://www.neo4j.com/developer/`,
type: 'link'
},
{
name: 'Knowledge Base',
command: `https://neo4j.com/developer/kb/`,
type: 'link'
}
]

const getStaticItems = version => {
return {
help,
intro,
reference: getReferences(version)
}
}

const Documents = ({ items = {} }) => {
return (
<Drawer id='db-documents'>
<DrawerHeader>Documents</DrawerHeader>
Expand All @@ -80,4 +94,10 @@ const Documents = ({ items = staticItems }) => {
)
}

export default Documents
const mapStateToProps = state => {
return {
items: getStaticItems(formatDocVersion(getVersion(state)))
}
}

export default connect(mapStateToProps)(Documents)
39 changes: 39 additions & 0 deletions src/browser/modules/Sidebar/docsUtils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2002-2018 "Neo4j, Inc"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* global describe, test, expect */

import { formatDocVersion } from './Documents'

test('formatDocVersion', () => {
const tests = [
{ test: null, expect: 'current' },
{ test: undefined, expect: 'current' },
{ test: true, expect: 'current' },
{ test: false, expect: 'current' },
{ test: '', expect: 'current' },
{ test: '1.1.0', expect: '1.1' },
{ test: '1.1.0-beta01', expect: '1.1' },
{ test: '1.1.2', expect: '1.1' },
{ test: '2.1.10', expect: '2.1' }
]

tests.forEach(t => expect(formatDocVersion(t.test)).toEqual(t.expect))
})