Skip to content

Commit 3c44593

Browse files
authored
Remove deprecated procedures (#1808)
* Remove deprecated procedures * update e2e tests * Refactor schemaFrame * replace version getter in schema frame
1 parent 053b4fa commit 3c44593

File tree

4 files changed

+385
-22
lines changed

4 files changed

+385
-22
lines changed

e2e_tests/integration/schema-frame.spec.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,26 @@ describe('Schema Frame', () => {
103103
cy.executeCommand(':clear')
104104
cy.executeCommand(':schema')
105105

106-
cy.get('[data-testid="frameContents"]')
107-
.should('contain', 'Constraints')
108-
.and('contain', ':SchemaTest')
106+
if (Cypress.config('serverVersion') >= 4.2) {
107+
// Headers
108+
cy.get('[data-testid="frameContents"]')
109+
.should('contain', 'Constraint Name')
110+
.and('contain', 'Type')
111+
.and('contain', 'EntityType')
112+
.and('contain', 'LabelsOrTypes')
113+
.and('contain', 'Properties')
114+
115+
// Constraint info
116+
cy.get('[data-testid="frameContents"]')
117+
.should('contain', 'UNIQUENESS')
118+
.and('contain', 'NODE')
119+
.and('contain', '"SchemaTest"')
120+
.and('contain', '"prop1"')
121+
} else {
122+
cy.get('[data-testid="frameContents"]')
123+
.should('contain', 'Constraints')
124+
.and('contain', ':SchemaTest')
125+
}
109126
})
110127
})
111128
})

src/browser/modules/Stream/SchemaFrame.test.tsx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,71 @@ test('SchemaFrame renders empty for Neo4j >= 4.0', () => {
4848
expect(container).toMatchSnapshot()
4949
})
5050

51+
test('SchemaFrame renders results for Neo4j >= 4.2', () => {
52+
const indexResult = {
53+
success: true,
54+
result: {
55+
records: [
56+
{
57+
_fields: [
58+
'INDEX ON :Movie(released)',
59+
'Movie',
60+
['released'],
61+
'ONLINE',
62+
'node_label_property',
63+
{
64+
version: '2.0',
65+
key: 'lucene+native'
66+
}
67+
],
68+
keys: [
69+
'description',
70+
'label',
71+
'properties',
72+
'state',
73+
'type',
74+
'provider'
75+
]
76+
}
77+
]
78+
}
79+
}
80+
const firstIndexRecord: any = indexResult.result.records[0]
81+
firstIndexRecord.get = (key: any) =>
82+
firstIndexRecord._fields[firstIndexRecord.keys.indexOf(key)]
83+
84+
const constraintResult = {
85+
success: true,
86+
result: {
87+
records: [
88+
{
89+
keys: ['name', 'type', 'entityType', 'labelsOrTypes', 'properties'],
90+
_fields: [
91+
'constraint_550b2518',
92+
'UNIQUE',
93+
'node',
94+
['Movie'],
95+
['released']
96+
]
97+
}
98+
]
99+
}
100+
}
101+
const firstConstraintRecord: any = constraintResult.result.records[0]
102+
firstConstraintRecord.get = (key: any) =>
103+
firstConstraintRecord._fields[firstConstraintRecord.keys.indexOf(key)]
104+
105+
const { container } = renderWithRedux(
106+
<SchemaFrame
107+
indexes={indexResult}
108+
constraints={constraintResult}
109+
neo4jVersion={'4.2.1'}
110+
/>
111+
)
112+
113+
expect(container).toMatchSnapshot()
114+
})
115+
51116
test('SchemaFrame renders results for Neo4j < 4.0', () => {
52117
const indexResult = {
53118
success: true,

src/browser/modules/Stream/SchemaFrame.tsx

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { replace, toUpper } from 'lodash-es'
2121
import React, { Component } from 'react'
2222
import { connect } from 'react-redux'
2323
import { withBus } from 'react-suber'
24-
import semver from 'semver'
24+
import semver, { SemVer } from 'semver'
2525
import { v4 } from 'uuid'
2626

2727
import Slide from '../Carousel/Slide'
@@ -36,11 +36,11 @@ import Directives from 'browser-components/Directives'
3636
import { GlobalState } from 'project-root/src/shared/globalState'
3737
import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata'
3838
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
39-
import { getRawVersion } from 'shared/modules/dbMeta/dbMetaDuck'
39+
import { getSemanticVersion } from 'shared/modules/dbMeta/dbMetaDuck'
4040

4141
type IndexesProps = {
4242
indexes: any
43-
neo4jVersion: string | null
43+
neo4jVersion: SemVer | null
4444
}
4545
const Indexes = ({ indexes, neo4jVersion }: IndexesProps) => {
4646
if (
@@ -90,15 +90,44 @@ const Indexes = ({ indexes, neo4jVersion }: IndexesProps) => {
9090
)
9191
}
9292

93-
const Constraints = ({ constraints }: any) => {
94-
const rows = constraints.map((constraint: any) => [
95-
replace(constraint.description, 'CONSTRAINT', '')
96-
])
93+
const Constraints = ({
94+
constraints,
95+
neo4jVersion
96+
}: {
97+
constraints: any
98+
neo4jVersion: string
99+
}) => {
100+
let rows = []
101+
let header = []
102+
103+
if (semver.valid(neo4jVersion) && semver.satisfies(neo4jVersion, '<4.2.*')) {
104+
header = ['Constraints']
105+
106+
rows = constraints.map((constraint: any) => [
107+
replace(constraint.description, 'CONSTRAINT', '')
108+
])
109+
} else {
110+
header = [
111+
'Constraint Name',
112+
'Type',
113+
'EntityType',
114+
'LabelsOrTypes',
115+
'Properties'
116+
]
117+
118+
rows = constraints.map((constraint: any) => [
119+
constraint.name,
120+
constraint.type,
121+
constraint.entityType,
122+
JSON.stringify(constraint.labelsOrTypes, null, 2),
123+
JSON.stringify(constraint.properties, null, 2)
124+
])
125+
}
97126

98127
return (
99128
<SchemaTable
100129
testid="schemaFrameConstraintsTable"
101-
header={['Constraints']}
130+
header={header}
102131
rows={rows}
103132
/>
104133
)
@@ -139,7 +168,7 @@ const SchemaTable = ({ testid, header, rows }: any) => {
139168
type SchemaFrameState = any
140169

141170
export class SchemaFrame extends Component<any, SchemaFrameState> {
142-
constructor(props: {}) {
171+
constructor(props: { neo4jVersion: string }) {
143172
super(props)
144173
this.state = {
145174
indexes: [],
@@ -163,13 +192,17 @@ export class SchemaFrame extends Component<any, SchemaFrameState> {
163192
}
164193
}
165194

166-
fetchData() {
195+
fetchData(neo4jVersion: SemVer) {
167196
if (this.props.bus) {
168197
// Indexes
169198
this.props.bus.self(
170199
CYPHER_REQUEST,
171200
{
172-
query: 'CALL db.indexes()',
201+
query:
202+
semver.valid(neo4jVersion) &&
203+
semver.satisfies(neo4jVersion, '<4.2.*')
204+
? 'CALL db.indexes()'
205+
: 'SHOW INDEXES',
173206
queryType: NEO4J_BROWSER_USER_ACTION_QUERY
174207
},
175208
this.responseHandler('indexes')
@@ -178,15 +211,19 @@ export class SchemaFrame extends Component<any, SchemaFrameState> {
178211
this.props.bus.self(
179212
CYPHER_REQUEST,
180213
{
181-
query: 'CALL db.constraints()',
214+
query:
215+
semver.valid(neo4jVersion) &&
216+
semver.satisfies(neo4jVersion, '<4.2.*')
217+
? 'CALL db.constraints()'
218+
: 'SHOW CONSTRAINTS',
182219
queryType: NEO4J_BROWSER_USER_ACTION_QUERY
183220
},
184221
this.responseHandler('constraints')
185222
)
186223
}
187224
}
188225
componentDidMount() {
189-
this.fetchData()
226+
this.fetchData(this.props.neo4jVersion)
190227
if (this.props.indexes) {
191228
this.responseHandler('indexes')(this.props.indexes)
192229
}
@@ -200,11 +237,11 @@ export class SchemaFrame extends Component<any, SchemaFrameState> {
200237
this.props.frame &&
201238
this.props.frame.schemaRequestId !== prevProps.frame.schemaRequestId
202239
) {
203-
this.fetchData()
240+
this.fetchData(this.props.neo4jVersion)
204241
}
205242
}
206243

207-
render() {
244+
render(): JSX.Element {
208245
const { neo4jVersion } = this.props
209246
const { indexes, constraints } = this.state
210247
const schemaCommand =
@@ -215,7 +252,7 @@ export class SchemaFrame extends Component<any, SchemaFrameState> {
215252
const frame = (
216253
<Slide>
217254
<Indexes indexes={indexes} neo4jVersion={neo4jVersion} />
218-
<Constraints constraints={constraints} />
255+
<Constraints constraints={constraints} neo4jVersion={neo4jVersion} />
219256
<br />
220257
<p className="lead">
221258
Execute the following command to visualize what's related, and how
@@ -245,7 +282,7 @@ const Frame = (props: any) => {
245282
}
246283

247284
const mapStateToProps = (state: GlobalState) => ({
248-
neo4jVersion: getRawVersion(state)
285+
neo4jVersion: getSemanticVersion(state)
249286
})
250287

251288
export default withBus(connect(mapStateToProps, null)(Frame))

0 commit comments

Comments
 (0)