Skip to content

Commit

Permalink
Show number of nodes and rels in sidebar
Browse files Browse the repository at this point in the history
Count the number of nodes and relationships on every db-meta update
  • Loading branch information
oskarhane committed Jun 5, 2018
1 parent 2ab9b0e commit 2d5760e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/browser/modules/DatabaseInfo/DatabaseInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,25 @@ export class DatabaseInfo extends Component {
properties = [],
userDetails,
databaseKernelInfo,
onItemClick
onItemClick,
nodes,
relationships
} = this.props

return (
<Drawer id='db-drawer'>
<DrawerHeader>Database Information</DrawerHeader>
<DrawerBody>
<LabelItems
count={nodes}
labels={labels.slice(0, this.state.labelsMax).map(l => l.val)}
totalNumItems={labels.length}
onItemClick={onItemClick}
onMoreClick={this.onMoreClick.bind(this)('labels')}
moreStep={this.state.moreStep}
/>
<RelationshipItems
count={relationships}
relationshipTypes={relationshipTypes
.slice(0, this.state.relationshipsMax)
.map(l => l.val)}
Expand Down
23 changes: 17 additions & 6 deletions src/browser/modules/DatabaseInfo/MetaItems.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ const createItems = (
onItemClick,
RenderType,
editorCommandTemplate,
showStar = true
showStar = true,
count
) => {
let items = [...originalList]
if (showStar) {
items.unshift('*')
let str = '*'
if (count) {
str = `${str}(${count})`
}
items.unshift(str)
}
return items.map((text, index) => {
const getNodesCypher = editorCommandTemplate(text, index)
Expand All @@ -81,7 +86,8 @@ const LabelItems = ({
totalNumItems,
onItemClick,
moreStep,
onMoreClick
onMoreClick,
count
}) => {
let labelItems = <p>There are no labels in database</p>
if (labels.length) {
Expand All @@ -95,7 +101,9 @@ const LabelItems = ({
labels,
onItemClick,
{ component: StyledLabel },
editorCommandTemplate
editorCommandTemplate,
true,
count
)
}
return (
Expand All @@ -122,7 +130,8 @@ const RelationshipItems = ({
totalNumItems,
onItemClick,
moreStep,
onMoreClick
onMoreClick,
count
}) => {
let relationshipItems = <p>No relationships in database</p>
if (relationshipTypes.length > 0) {
Expand All @@ -138,7 +147,9 @@ const RelationshipItems = ({
relationshipTypes,
onItemClick,
{ component: StyledRelationship },
editorCommandTemplate
editorCommandTemplate,
true,
count
)
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ Object {
"foo": "bar",
"functions": Array [],
"labels": Array [],
"nodes": 0,
"procedures": Array [],
"properties": Array [],
"relationshipTypes": Array [],
"relationships": 0,
"role": null,
"server": Object {
"dbName": null,
Expand All @@ -27,9 +29,11 @@ exports[`updating metadata can CLEAR to reset state 1`] = `
Object {
"functions": Array [],
"labels": Array [],
"nodes": 0,
"procedures": Array [],
"properties": Array [],
"relationshipTypes": Array [],
"relationships": 0,
"role": null,
"server": Object {
"dbName": null,
Expand Down
17 changes: 16 additions & 1 deletion src/shared/modules/dbMeta/dbMetaDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function updateMetaForContext (state, meta, context) {
const mapResult = (metaIndex, mapFunction) =>
meta.records[metaIndex].get(1).map(mapFunction)
const mapSingleValue = r => ({ val: r, context })
const mapInteger = r => (bolt.neo4j.isInt(r) ? r.toNumber() || 0 : r || 0)
const mapInvocableValue = r => {
const { name, signature, description } = r
return {
Expand Down Expand Up @@ -154,18 +155,28 @@ function updateMetaForContext (state, meta, context) {
const procedures = state.procedures
.filter(notInCurrentContext)
.concat(mapResult(4, mapInvocableValue))
const nodes = meta.records[5]
? mapInteger(meta.records[5].get(1))
: state.nodes
const relationships = meta.records[6]
? mapInteger(meta.records[6].get(1))
: state.relationships

return {
labels,
relationshipTypes,
properties,
functions,
procedures
procedures,
nodes,
relationships
}
}

// Initial state
const initialState = {
nodes: 0,
relationships: 0,
labels: [],
relationshipTypes: [],
properties: [],
Expand Down Expand Up @@ -266,6 +277,10 @@ UNION
CALL dbms.procedures() YIELD name, signature, description
WITH collect({name: name, signature: signature, description: description}) as procedures
RETURN 'procedures' as a, procedures as result
UNION
MATCH (n) RETURN 'nodes' AS a, count(n) AS result
UNION
MATCH ()-[]->() RETURN 'relationships' AS a, count(*) AS result
`

export const dbMetaEpic = (some$, store) =>
Expand Down
23 changes: 21 additions & 2 deletions src/shared/modules/dbMeta/dbMetaDuck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

/* global describe, test, expect */
import { v1 as neo4j } from 'neo4j-driver-alias'
import reducer, * as meta from './dbMetaDuck'
import { APP_START } from 'shared/modules/app/appDuck'

Expand Down Expand Up @@ -78,6 +79,15 @@ describe('updating metadata', () => {
]
}
}
const returnedNodes = {
a: 'nodes',
get: () => neo4j.int(5)
}
const returnedRelationships = {
a: 'relationships',
get: () => neo4j.int(10)
}

const action = {
type: meta.UPDATE_META,
meta: {
Expand All @@ -86,7 +96,9 @@ describe('updating metadata', () => {
returnedRelationshipTypes,
returnedProperties,
returnedFunctions,
returnedProcedures
returnedProcedures,
returnedNodes,
returnedRelationships
]
},
context: 'mycontext'
Expand Down Expand Up @@ -122,10 +134,13 @@ describe('updating metadata', () => {
description: 'procedureDescription'
}
])
expect(nextState.nodes).toEqual(5)
expect(nextState.relationships).toEqual(10)
})

test('should update state with empty metadata', () => {
const returnNothing = () => []
const returnNull = () => null
const action = {
type: meta.UPDATE_META,
meta: {
Expand All @@ -134,7 +149,9 @@ describe('updating metadata', () => {
{ a: 'relationshipTypes', get: returnNothing },
{ a: 'properties', get: returnNothing },
{ a: 'functions', get: returnNothing },
{ a: 'procedures', get: returnNothing }
{ a: 'procedures', get: returnNothing },
{ a: 'nodes', get: returnNull },
{ a: 'realtionships', get: returnNull }
]
},
context: 'mycontext'
Expand All @@ -147,6 +164,8 @@ describe('updating metadata', () => {
expect(nextState.properties).toEqual([])
expect(nextState.functions).toEqual([])
expect(nextState.procedures).toEqual([])
expect(nextState.nodes).toEqual(0)
expect(nextState.relationships).toEqual(0)
})
test('can update server settings', () => {
// Given
Expand Down

0 comments on commit 2d5760e

Please sign in to comment.