Skip to content

Commit eac0ed1

Browse files
author
Jas Kuner
authored
Format node/relationship counts in sidebar, inspector and legend (#1008)
* commas-node-and-relation-count-new: initial * commas-node-and-relation-count-new: thousand comma separation utility created. naming needs looking at. * commas-node-and-relation-count: remove a classname added just for a test build * commas-node-and-relation-count-new: rename util to be more suitable and rework the function with logical operators * commas-node-and-relation-count-new: used alias for shared utils import path, added additional tests and reworked number-to-US-locale.js to allow 0 to be output as string to be consistent with other values * commas-node-and-relation-count-new: remove accidentally inserted local mock for node and relationship values
1 parent 234d4c2 commit eac0ed1

File tree

5 files changed

+125
-10
lines changed

5 files changed

+125
-10
lines changed

src/browser/modules/D3Visualization/components/Inspector.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ import {
3939
import { GrassEditor } from './GrassEditor'
4040
import { RowExpandToggleComponent } from './RowExpandToggle'
4141
import ClickableUrls from '../../../components/clickable-urls'
42+
import numberToUSLocale from 'shared/utils/number-to-US-locale'
4243

4344
const mapItemProperties = itemProperties =>
4445
itemProperties
45-
.sort(
46-
({ key: keyA }, { key: keyB }) =>
47-
keyA < keyB ? -1 : keyA === keyB ? 0 : 1
46+
.sort(({ key: keyA }, { key: keyB }) =>
47+
keyA < keyB ? -1 : keyA === keyB ? 0 : 1
4848
)
4949
.map((prop, i) => (
5050
<StyledInspectorFooterRowListPair className='pair' key={'prop' + i}>
@@ -142,9 +142,9 @@ export class InspectorComponent extends Component {
142142
</StyledInlineList>
143143
)
144144
} else if (type === 'canvas') {
145-
const description = `Displaying ${item.nodeCount} nodes, ${
146-
item.relationshipCount
147-
} relationships.`
145+
const description = `Displaying ${numberToUSLocale(
146+
item.nodeCount
147+
)} nodes, ${numberToUSLocale(item.relationshipCount)} relationships.`
148148
inspectorContent = (
149149
<StyledInlineList className='list-inline'>
150150
<StyledInspectorFooterRowListPair className='pair' key='pair'>

src/browser/modules/D3Visualization/components/Legend.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
StyledLegendInlineList
3232
} from './styled'
3333
import { RowExpandToggleComponent } from './RowExpandToggle'
34+
import numberToUSLocale from 'shared/utils/number-to-US-locale'
3435

3536
export class LegendComponent extends Component {
3637
constructor (props) {
@@ -75,9 +76,9 @@ export class LegendComponent extends Component {
7576
className='token token-label'
7677
>
7778
{legendItemKey}
78-
<StyledTokenCount className='count'>{`(${
79+
<StyledTokenCount className='count'>{`(${numberToUSLocale(
7980
labels[legendItemKey].count
80-
})`}</StyledTokenCount>
81+
)})`}</StyledTokenCount>
8182
</StyledLabelToken>
8283
</StyledLegendContents>
8384
</StyledLegendInlineListItem>
@@ -134,7 +135,7 @@ export class LegendComponent extends Component {
134135
>
135136
{legendItemKey}
136137
<StyledTokenCount className='count'>
137-
{`(${legendItems[legendItemKey].count})`}
138+
{`(${numberToUSLocale(legendItems[legendItemKey].count)})`}
138139
</StyledTokenCount>
139140
</StyledTokenRelationshipType>
140141
</StyledLegendContents>

src/browser/modules/DBMSInfo/MetaItems.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
StyledShowMoreLink
3535
} from './styled'
3636
import Render from 'browser-components/Render'
37+
import numberToUSLocale from 'shared/utils/number-to-US-locale'
3738

3839
const ShowMore = ({ total, shown, moreStep, onMore }) => {
3940
const numMore = total - shown > moreStep ? moreStep : total - shown
@@ -64,7 +65,7 @@ const createItems = (
6465
if (showStar) {
6566
let str = '*'
6667
if (count) {
67-
str = `${str}(${count})`
68+
str = `${str}(${numberToUSLocale(count)})`
6869
}
6970
items.unshift(str)
7071
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2002-2019 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
* This file is part of Neo4j.
5+
* Neo4j is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*
16+
*/
17+
18+
export default value =>
19+
(parseInt(value, 10) >= 0 && parseInt(value, 10).toLocaleString('en-US')) ||
20+
value
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2002-2019 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
/* global describe, test, expect */
22+
import numberToUSLocale from './number-to-US-locale'
23+
24+
describe('numberToUSLocale', () => {
25+
test('should return the original value if isNaN(value) is true', () => {
26+
// Given
27+
const value = null
28+
29+
// When
30+
const returnValue = numberToUSLocale(value)
31+
32+
// Then
33+
expect(returnValue).toBe(value)
34+
})
35+
test('should return a non-comma separated number if isNaN(value) is false and 0 <= value < 1000', () => {
36+
let value, returnValue
37+
// Given
38+
value = 0
39+
40+
// When
41+
returnValue = numberToUSLocale(value)
42+
43+
// Then
44+
expect(returnValue).toBe('0')
45+
46+
// Given
47+
value = '10'
48+
49+
// When
50+
returnValue = numberToUSLocale(value)
51+
52+
// Then
53+
expect(returnValue).toBe('10')
54+
55+
// Given
56+
value = 999
57+
58+
// When
59+
returnValue = numberToUSLocale(value)
60+
61+
// Then
62+
expect(returnValue).toBe('999')
63+
})
64+
test('should return a thousands comma separated number if isNaN(value) is false and value >= 1000 ', () => {
65+
let value, returnValue
66+
// Given
67+
value = 1000
68+
69+
// When
70+
returnValue = numberToUSLocale(value)
71+
72+
// Then
73+
expect(returnValue).toBe('1,000')
74+
75+
// Given
76+
value = '123456789'
77+
78+
// When
79+
returnValue = numberToUSLocale(value)
80+
81+
// Then
82+
expect(returnValue).toBe('123,456,789')
83+
84+
// Given
85+
value = 987654312345
86+
87+
// When
88+
returnValue = numberToUSLocale(value)
89+
90+
// Then
91+
expect(returnValue).toBe('987,654,312,345')
92+
})
93+
})

0 commit comments

Comments
 (0)