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

Format node/relationship counts in sidebar, inspector and legend #1008

Merged
merged 6 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 6 additions & 6 deletions src/browser/modules/D3Visualization/components/Inspector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ import {
import { GrassEditor } from './GrassEditor'
import { RowExpandToggleComponent } from './RowExpandToggle'
import ClickableUrls from '../../../components/clickable-urls'
import numberToUSLocale from '../../../../shared/utils/number-to-US-locale'
oskarhane marked this conversation as resolved.
Show resolved Hide resolved

const mapItemProperties = itemProperties =>
itemProperties
.sort(
({ key: keyA }, { key: keyB }) =>
keyA < keyB ? -1 : keyA === keyB ? 0 : 1
.sort(({ key: keyA }, { key: keyB }) =>
keyA < keyB ? -1 : keyA === keyB ? 0 : 1
)
.map((prop, i) => (
<StyledInspectorFooterRowListPair className='pair' key={'prop' + i}>
Expand Down Expand Up @@ -142,9 +142,9 @@ export class InspectorComponent extends Component {
</StyledInlineList>
)
} else if (type === 'canvas') {
const description = `Displaying ${item.nodeCount} nodes, ${
item.relationshipCount
} relationships.`
const description = `Displaying ${numberToUSLocale(
item.nodeCount
)} nodes, ${numberToUSLocale(item.relationshipCount)} relationships.`
inspectorContent = (
<StyledInlineList className='list-inline'>
<StyledInspectorFooterRowListPair className='pair' key='pair'>
Expand Down
7 changes: 4 additions & 3 deletions src/browser/modules/D3Visualization/components/Legend.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
StyledLegendInlineList
} from './styled'
import { RowExpandToggleComponent } from './RowExpandToggle'
import numberToUSLocale from '../../../../shared/utils/number-to-US-locale'

export class LegendComponent extends Component {
constructor (props) {
Expand Down Expand Up @@ -75,9 +76,9 @@ export class LegendComponent extends Component {
className='token token-label'
>
{legendItemKey}
<StyledTokenCount className='count'>{`(${
<StyledTokenCount className='count'>{`(${numberToUSLocale(
labels[legendItemKey].count
})`}</StyledTokenCount>
)})`}</StyledTokenCount>
</StyledLabelToken>
</StyledLegendContents>
</StyledLegendInlineListItem>
Expand Down Expand Up @@ -134,7 +135,7 @@ export class LegendComponent extends Component {
>
{legendItemKey}
<StyledTokenCount className='count'>
{`(${legendItems[legendItemKey].count})`}
{`(${numberToUSLocale(legendItems[legendItemKey].count)})`}
</StyledTokenCount>
</StyledTokenRelationshipType>
</StyledLegendContents>
Expand Down
3 changes: 2 additions & 1 deletion src/browser/modules/DBMSInfo/MetaItems.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
StyledShowMoreLink
} from './styled'
import Render from 'browser-components/Render'
import numberToUSLocale from '../../../shared/utils/number-to-US-locale'

const ShowMore = ({ total, shown, moreStep, onMore }) => {
const numMore = total - shown > moreStep ? moreStep : total - shown
Expand Down Expand Up @@ -64,7 +65,7 @@ const createItems = (
if (showStar) {
let str = '*'
if (count) {
str = `${str}(${count})`
str = `${str}(${numberToUSLocale(count)})`
}
items.unshift(str)
}
Expand Down
19 changes: 19 additions & 0 deletions src/shared/utils/number-to-US-locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2002-2019 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.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/>.
*
*/

export default value =>
(parseInt(value, 10) && parseInt(value, 10).toLocaleString('en-US')) || value
oskarhane marked this conversation as resolved.
Show resolved Hide resolved
55 changes: 55 additions & 0 deletions src/shared/utils/number-to-US-locale.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2002-2019 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.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 numberToUSLocale from './number-to-US-locale'

describe('numberToUSLocale', () => {
test('should return the original value if isNaN(value) is true', () => {
// Given
const value = null

// When
const returnValue = numberToUSLocale(value)

// Then
expect(returnValue).toBe(value)
})
test('should return a thousands comma separated number if isNaN(value) is false', () => {
let value, returnValue
// Given
value = '123456789'

// When
returnValue = numberToUSLocale(value)

// Then
expect(returnValue).toBe('123,456,789')

// Given
value = 987654312345

// When
returnValue = numberToUSLocale(value)

// Then
expect(returnValue).toBe('987,654,312,345')
})
oskarhane marked this conversation as resolved.
Show resolved Hide resolved
})