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

Make sure path start / end nodes aren’t "type stamped" twice #762

Merged
merged 2 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions e2e_tests/integration/types.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,16 @@ describe('Types in Browser', () => {
.should('contain', 'date: "P11M3DT-78036.143000000S"')
.and('contain', 'location: point({srid:4326, x:12.78, y:56.7})')
})
it('renders types in paths in viz correctly', () => {
cy.executeCommand(':clear')
const query = 'MATCH p=(:Types) RETURN p'
cy.executeCommand(query)
// cy.waitForCommandResult()
cy.get('circle.outline', { timeout: 10000 }).click()
cy
.get('[data-test-id="vizInspector"]')
.should('contain', 'date: "P11M3DT-78036.143000000S"')
.and('contain', 'location: point({srid:4326, x:12.78, y:56.7})')
})
}
})
56 changes: 56 additions & 0 deletions src/shared/services/bolt/applyGraphTypes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,62 @@ describe('applyGraphTypes', () => {
const typedDate = applyGraphTypes(rawDate)
expect(typedDate).toBeInstanceOf(neo4j.types.Time)
})
test('should identify time in nodes in paths with refs for start and end', () => {
const date = new neo4j.types.Time(11, 1, 12, 3600)
const start = new neo4j.types.Node(neo4j.int(1), ['From'], { date })
const end = new neo4j.types.Node(neo4j.int(3), ['To'], {})
const rel = new neo4j.types.Relationship(
neo4j.int(2),
neo4j.int(1),
neo4j.int(3),
'TestType',
{}
)
const seg = new neo4j.types.PathSegment(start, rel, end)
const segments = [seg]
const path = new neo4j.types.Path(
segments[0].start,
segments[segments.length - 1].end,
segments
)

// When
const res = nativeTypesToCustom(path)
const typed = applyGraphTypes(res)

// Then
expect(typed.start.properties.date instanceof neo4j.types.Time).toBeTruthy()
expect(
typed.segments[0].start.properties.date instanceof neo4j.types.Time
).toBeTruthy()
})
test('should identify time in nodes in paths', () => {
const date = new neo4j.types.Time(11, 1, 12, 3600)
const start = new neo4j.types.Node(neo4j.int(1), ['From'], { date })
const segmentStart = new neo4j.types.Node(neo4j.int(1), ['From'], { date })
const end = new neo4j.types.Node(neo4j.int(3), ['To'], {})
const segmentEnd = new neo4j.types.Node(neo4j.int(3), ['To'], {})
const rel = new neo4j.types.Relationship(
neo4j.int(2),
neo4j.int(1),
neo4j.int(3),
'TestType',
{}
)
const seg = new neo4j.types.PathSegment(segmentStart, rel, segmentEnd)
const segments = [seg]
const path = new neo4j.types.Path(start, end, segments)

// When
const res = nativeTypesToCustom(path)
const typed = applyGraphTypes(res)

// Then
expect(typed.start.properties.date instanceof neo4j.types.Time).toBeTruthy()
expect(
typed.segments[0].start.properties.date instanceof neo4j.types.Time
).toBeTruthy()
})
})

const nativeTypesToCustom = x => {
Expand Down
16 changes: 12 additions & 4 deletions src/shared/services/bolt/boltMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
safetlyRemoveObjectProp,
safetlyAddObjectProp,
escapeReservedProps,
unEscapeReservedProps
unEscapeReservedProps,
hasReservedProp
} from '../utils'

export const reservedTypePropertyName = 'transport-class'
Expand Down Expand Up @@ -136,7 +137,10 @@ const collectHits = function (operator) {
return hits
}

export function extractNodesAndRelationshipsFromRecords (records, types) {
export function extractNodesAndRelationshipsFromRecords (
records,
types = neo4j.types
) {
if (records.length === 0) {
return { nodes: [], relationships: [] }
}
Expand Down Expand Up @@ -432,8 +436,12 @@ export const recursivelyTypeGraphItems = (item, types = neo4j.types) => {
if (item instanceof types.Path) {
safetlyAddObjectProp(item, reservedTypePropertyName, 'Path')
item.segments = item.segments.map(x => recursivelyTypeGraphItems(x, types))
item.start = recursivelyTypeGraphItems(item.start, types)
item.end = recursivelyTypeGraphItems(item.end, types)
item.start = !hasReservedProp(item.start, reservedTypePropertyName)
? recursivelyTypeGraphItems(item.start, types)
: item.start
item.end = !hasReservedProp(item.end, reservedTypePropertyName)
? recursivelyTypeGraphItems(item.end, types)
: item.end
return item
}
if (item instanceof types.Relationship) {
Expand Down
11 changes: 7 additions & 4 deletions src/shared/services/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export const safetlyAddObjectProp = (obj, prop, val) => {
}

export const safetlyRemoveObjectProp = (obj, prop) => {
if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
if (!hasReservedProp(obj, prop)) {
return obj
}
delete obj[prop]
Expand All @@ -357,7 +357,7 @@ export const safetlyRemoveObjectProp = (obj, prop) => {
}

export const escapeReservedProps = (obj, prop) => {
if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
if (!hasReservedProp(obj, prop)) {
return obj
}
obj = safetlyAddObjectProp(obj, getEscapedObjectProp(prop), obj[prop])
Expand All @@ -367,11 +367,11 @@ export const escapeReservedProps = (obj, prop) => {

export const unEscapeReservedProps = (obj, prop) => {
let propName = getEscapedObjectProp(prop)
if (!Object.prototype.hasOwnProperty.call(obj, propName)) {
if (!hasReservedProp(obj, propName)) {
return obj
}
while (true) {
if (!Object.prototype.hasOwnProperty.call(obj, propName)) {
if (!hasReservedProp(obj, propName)) {
break
}
obj[getUnescapedObjectProp(propName)] = obj[propName]
Expand All @@ -385,5 +385,8 @@ const getEscapedObjectProp = prop => `\\${prop}`
const getUnescapedObjectProp = prop =>
prop.indexOf('\\') === 0 ? prop.substr(1) : prop // A bit weird because of escape chars

export const hasReservedProp = (obj, propName) =>
Object.prototype.hasOwnProperty.call(obj, propName)

// Epic helpers
export const put = dispatch => action => dispatch(action)