diff --git a/package.json b/package.json
index 315a6a63d83..858f1f06825 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/browser/modules/Sidebar/Documents.jsx b/src/browser/modules/Sidebar/Documents.jsx
index 4ca2d345dd3..53aeb7ee243 100644
--- a/src/browser/modules/Sidebar/Documents.jsx
+++ b/src/browser/modules/Sidebar/Documents.jsx
@@ -18,56 +18,70 @@
* along with this program. If not, see .
*/
+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 (
Documents
@@ -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)
diff --git a/src/browser/modules/Sidebar/docsUtils.test.js b/src/browser/modules/Sidebar/docsUtils.test.js
new file mode 100644
index 00000000000..c83ff6c696a
--- /dev/null
+++ b/src/browser/modules/Sidebar/docsUtils.test.js
@@ -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 .
+ */
+
+/* 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))
+})