Skip to content

Commit fc60d6a

Browse files
Fix formatting of large duration values (#1958)
* Remove luxon duration formatter * fix duration issue * self review * fix unit test * fix e2e test and add new test * update type spec * fix tests and restore older rendering in ascii view
1 parent 364127c commit fc60d6a

File tree

9 files changed

+328
-341
lines changed

9 files changed

+328
-341
lines changed

LICENSES.txt

Lines changed: 206 additions & 114 deletions
Large diffs are not rendered by default.

NOTICE.txt

Lines changed: 43 additions & 164 deletions
Large diffs are not rendered by default.

e2e_tests/integration/types.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ describe('Types in Browser', () => {
106106
cy.executeCommand(query)
107107
cy.waitForCommandResult()
108108

109-
cy.resultContains('P1Y2M3DT4H5M6S')
109+
cy.resultContains('P14M3DT14706S')
110110
// Go to ascii view
111111
cy.get('[data-testid="cypherFrameSidebarAscii"]').first().click()
112-
cy.resultContains('│P1Y2M3DT4H5M6S')
112+
cy.resultContains('│"P14M3DT14706S')
113113
})
114114
it('presents time type correctly', () => {
115115
cy.executeCommand(':clear')
@@ -143,7 +143,7 @@ describe('Types in Browser', () => {
143143
// cy.waitForCommandResult()
144144
cy.get('circle.b-outline', { timeout: 10000 }).click()
145145
cy.get('[data-testid="vizInspector"]')
146-
.should('contain', 'P11M2DT2H19')
146+
.should('contain', 'P11M2DT8363.857000000S')
147147
.and('contain', 'srid:4326')
148148
.and('contain', 'elementId')
149149
})
@@ -154,7 +154,7 @@ describe('Types in Browser', () => {
154154
// cy.waitForCommandResult()
155155
cy.get('circle.b-outline', { timeout: 10000 }).click()
156156
cy.get('[data-testid="vizInspector"]')
157-
.should('contain', 'P11M2DT2H19')
157+
.should('contain', 'P11M2DT8363.857000000S')
158158
.and('contain', 'srid:4326')
159159
.and('contain', 'date')
160160
.and('contain', 'location')

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
"@types/jest": "^24.9.0",
9393
"@types/jsonic": "^0.3.0",
9494
"@types/lodash-es": "^4.17.6",
95-
"@types/luxon": "^2.0.3",
9695
"@types/react": "^17.0.40",
9796
"@types/react-dom": "^17.0.11",
9897
"@types/react-redux": "^7.1.9",
@@ -204,7 +203,6 @@
204203
"jsonic": "^0.3.0",
205204
"jszip": "3.8.0",
206205
"lodash-es": "^4.17.21",
207-
"luxon": "2.5.2",
208206
"memoize-one": "^5.2.1",
209207
"monaco-editor": "0.23.0",
210208
"neo4j-client-sso": "1.2.3",

src/browser/modules/Stream/CypherFrame/helpers.test.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
import neo4j, { Record } from 'neo4j-driver'
20+
import neo4j, { Integer, Record } from 'neo4j-driver'
2121

22+
import * as viewTypes from 'shared/modules/frames/frameViewTypes'
23+
import { BrowserRequestResult } from 'shared/modules/requests/requestsDuck'
2224
import {
23-
recordToStringArray,
2425
getRecordsToDisplayInTable,
2526
initialView,
2627
recordToJSONMapper,
28+
recordToStringArray,
2729
resultHasNodes,
2830
resultHasPlan,
2931
resultHasRows,
3032
resultHasWarnings,
3133
resultIsError
3234
} from './helpers'
33-
import * as viewTypes from 'shared/modules/frames/frameViewTypes'
34-
import { BrowserRequestResult } from 'shared/modules/requests/requestsDuck'
3535

3636
describe('helpers', () => {
3737
test('getRecordsToDisplayInTable should report if there are rows or not in the result', () => {
@@ -646,7 +646,7 @@ describe('helpers', () => {
646646
const res = records.map(record => recordToStringArray(record))
647647

648648
// Then
649-
expect(res).toEqual([['P1M2DT3S']])
649+
expect(res).toEqual([['"P1M2DT3.000000004S"']])
650650
})
651651
})
652652

@@ -846,7 +846,34 @@ describe('helpers', () => {
846846
elementType: 'node',
847847
labels: ['foo'],
848848
properties: {
849-
bar: 'P2012Y2M2DT14H37M21.545S'
849+
bar: 'P24146M2DT52641.545000000S'
850+
}
851+
}
852+
}
853+
854+
expect(recordToJSONMapper(record)).toEqual(expected)
855+
})
856+
857+
test('handles duration above js safe number', () => {
858+
const node = new (neo4j.types.Node as any)(1, ['foo'], {
859+
bar: new neo4j.types.Duration(
860+
new Integer(0),
861+
new Integer(0),
862+
// RETURN 9223372036854775807 which is maxiumum integer in neo4j
863+
new Integer(-1, 2147483647),
864+
new Integer(0)
865+
)
866+
})
867+
const record = new (neo4j.types.Record as any)(['n'], [node])
868+
const expected = {
869+
n: {
870+
elementId: '1',
871+
identity: 1,
872+
elementType: 'node',
873+
labels: ['foo'],
874+
properties: {
875+
// get same number as above
876+
bar: 'P0M0DT9223372036854775807S'
850877
}
851878
}
852879
}
@@ -866,7 +893,7 @@ describe('helpers', () => {
866893
elementType: 'node',
867894
labels: ['foo'],
868895
properties: {
869-
bar: 'PT1M40S'
896+
bar: 'P0M0DT100S'
870897
}
871898
}
872899
}

src/browser/modules/Stream/CypherFrame/helpers.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@ import {
3030
some
3131
} from 'lodash-es'
3232
import { CypherDataType, isCypherPropertyType } from 'neo4j-arc/common'
33-
import neo4j, { Path, Record, Node, Relationship } from 'neo4j-driver'
33+
import neo4j, { Node, Path, Record, Relationship } from 'neo4j-driver'
3434

3535
import bolt from 'services/bolt/bolt'
3636
import { recursivelyExtractGraphItems } from 'services/bolt/boltMappings'
37-
import {
38-
durationFormat,
39-
stringModifier
40-
} from 'services/bolt/cypherTypesFormatting'
37+
import { stringModifier } from 'services/bolt/cypherTypesFormatting'
4138
import { stringifyMod, unescapeDoubleQuotesForDisplay } from 'services/utils'
4239
import * as viewTypes from 'shared/modules/frames/frameViewTypes'
4340
import { BrowserRequestResult } from 'shared/modules/requests/requestsDuck'
@@ -396,7 +393,6 @@ export function mapNeo4jValuesToPlainValues(values: any): any {
396393
function neo4jValueToPlainValue(value: any) {
397394
switch (get(value, 'constructor')) {
398395
case neo4j.types.Duration:
399-
return durationFormat(value)
400396
case neo4j.types.Date:
401397
case neo4j.types.DateTime:
402398
case neo4j.types.LocalDateTime:

src/browser/modules/Stream/Queries/QueriesFrame.tsx

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ import { connect } from 'react-redux'
2222
import { withBus } from 'react-suber'
2323
import { Bus } from 'suber'
2424

25+
import { ConfirmationButton } from 'browser-components/buttons/ConfirmationButton'
26+
import { Duration } from 'neo4j-driver'
27+
import { GlobalState } from 'project-root/src/shared/globalState'
28+
import { gte } from 'semver'
29+
import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata'
30+
import {
31+
CONNECTED_STATE,
32+
getConnectionState
33+
} from 'shared/modules/connections/connectionsDuck'
34+
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
35+
import {
36+
getRawVersion,
37+
getSemanticVersion,
38+
hasProcedure,
39+
isOnCluster
40+
} from 'shared/modules/dbMeta/dbMetaDuck'
41+
import { Frame } from 'shared/modules/frames/framesDuck'
2542
import FrameBodyTemplate from '../../Frame/FrameBodyTemplate'
2643
import FrameError from '../../Frame/FrameError'
2744
import {
@@ -30,6 +47,9 @@ import {
3047
StatusbarWrapper,
3148
StyledStatusBar
3249
} from '../AutoRefresh/styled'
50+
import LegacyQueriesFrame, {
51+
LegacyQueriesFrameProps
52+
} from './LegacyQueriesFrame'
3353
import {
3454
Code,
3555
StyledHeaderRow,
@@ -38,26 +58,6 @@ import {
3858
StyledTd,
3959
StyledTh
4060
} from './styled'
41-
import { ConfirmationButton } from 'browser-components/buttons/ConfirmationButton'
42-
import { GlobalState } from 'project-root/src/shared/globalState'
43-
import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata'
44-
import {
45-
CONNECTED_STATE,
46-
getConnectionState
47-
} from 'shared/modules/connections/connectionsDuck'
48-
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
49-
import { durationFormat } from 'services/bolt/cypherTypesFormatting'
50-
import { Frame } from 'shared/modules/frames/framesDuck'
51-
import LegacyQueriesFrame, {
52-
LegacyQueriesFrameProps
53-
} from './LegacyQueriesFrame'
54-
import {
55-
getRawVersion,
56-
getSemanticVersion,
57-
hasProcedure,
58-
isOnCluster
59-
} from 'shared/modules/dbMeta/dbMetaDuck'
60-
import { gte } from 'semver'
6161

6262
type QueriesFrameState = {
6363
queries: any[]
@@ -84,6 +84,22 @@ function constructOverviewMessage(queries: any, errors: string[]) {
8484
: successMessage
8585
}
8686

87+
function prettyPrintDuration(duration: Duration) {
88+
const { months, days, seconds, nanoseconds } = duration
89+
90+
let resultsString = ''
91+
if (months.toNumber() > 0) {
92+
resultsString += `${months} months, `
93+
}
94+
if (days.toNumber() > 0) {
95+
resultsString += `${days} days, `
96+
}
97+
const millis = seconds.toNumber() * 1000 + nanoseconds.toNumber() / 1000000
98+
resultsString += `${millis} ms`
99+
100+
return resultsString
101+
}
102+
87103
export class QueriesFrame extends Component<
88104
QueriesFrameProps,
89105
QueriesFrameState
@@ -153,7 +169,7 @@ export class QueriesFrame extends Component<
153169
...data,
154170
host: `neo4j://${nonNullHost}`,
155171
query: data.currentQuery,
156-
elapsedTimeMillis: durationFormat(data.elapsedTime),
172+
elapsedTimeMillis: prettyPrintDuration(data.elapsedTime),
157173
queryId: data.transactionId
158174
}
159175
}
@@ -267,7 +283,7 @@ export class QueriesFrame extends Component<
267283
<Code>{JSON.stringify(query.metaData, null, 2)}</Code>
268284
</StyledTd>
269285
<StyledTd key="time" width={tableHeaderSizes[5][1]}>
270-
{query.elapsedTimeMillis} ms
286+
{query.elapsedTimeMillis}
271287
</StyledTd>
272288
<StyledTd key="actions" width={tableHeaderSizes[6][1]}>
273289
<ConfirmationButton

src/shared/services/bolt/cypherTypesFormatting.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Duration } from 'luxon'
21
import neo4j from 'neo4j-driver'
32

43
export const csvFormat = (anything: any) => {
@@ -31,21 +30,11 @@ export const stringModifier = (anything: any) => {
3130
return spacialFormat(anything)
3231
}
3332
if (isTemporalType(anything)) {
34-
if (isDuration(anything)) {
35-
return durationFormat(anything)
36-
} else {
37-
return `"${anything.toString()}"`
38-
}
33+
return `"${anything.toString()}"`
3934
}
4035
return undefined
4136
}
4237

43-
export const durationFormat = (duration: typeof neo4j.types.Duration): string =>
44-
Duration.fromISO(duration.toString())
45-
.shiftTo('years', 'days', 'months', 'hours', 'minutes', 'seconds')
46-
.normalize()
47-
.toISO()
48-
4938
const numberFormat = (anything: any) => {
5039
// Exclude false positives and return early
5140
if ([Infinity, -Infinity, NaN].includes(anything)) {

yarn.lock

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,11 +2366,6 @@
23662366
resolved "https://registry.npmjs.org/@types/long/-/long-4.0.1.tgz"
23672367
integrity "sha1-RZxl+hhn2v5qjzIsTFFpVmPMVek= sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w=="
23682368

2369-
"@types/luxon@^2.0.3":
2370-
version "2.4.0"
2371-
resolved "https://registry.npmjs.org/@types/luxon/-/luxon-2.4.0.tgz"
2372-
integrity sha512-oCavjEjRXuR6URJEtQm0eBdfsBiEcGBZbq21of8iGkeKxU1+1xgKuFPClaBZl2KB8ZZBSWlgk61tH6Mf+nvZVw==
2373-
23742369
"@types/mdast@^3.0.0":
23752370
version "3.0.3"
23762371
resolved "https://registry.npmjs.org/@types/mdast/-/mdast-3.0.3.tgz"
@@ -9096,11 +9091,6 @@ lru-cache@^6.0.0:
90969091
dependencies:
90979092
yallist "^4.0.0"
90989093

9099-
9100-
version "2.5.2"
9101-
resolved "https://registry.npmjs.org/luxon/-/luxon-2.5.2.tgz"
9102-
integrity sha512-Yg7/RDp4nedqmLgyH0LwgGRvMEKVzKbUdkBYyCosbHgJ+kaOUx0qzSiSatVc3DFygnirTPYnMM2P5dg2uH1WvA==
9103-
91049094
lz-string@^1.4.4:
91059095
version "1.4.4"
91069096
resolved "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz"

0 commit comments

Comments
 (0)