@@ -21,7 +21,7 @@ import { replace, toUpper } from 'lodash-es'
2121import React , { Component } from 'react'
2222import { connect } from 'react-redux'
2323import { withBus } from 'react-suber'
24- import semver from 'semver'
24+ import semver , { SemVer } from 'semver'
2525import { v4 } from 'uuid'
2626
2727import Slide from '../Carousel/Slide'
@@ -36,11 +36,11 @@ import Directives from 'browser-components/Directives'
3636import { GlobalState } from 'project-root/src/shared/globalState'
3737import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata'
3838import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
39- import { getRawVersion } from 'shared/modules/dbMeta/dbMetaDuck'
39+ import { getSemanticVersion } from 'shared/modules/dbMeta/dbMetaDuck'
4040
4141type IndexesProps = {
4242 indexes : any
43- neo4jVersion : string | null
43+ neo4jVersion : SemVer | null
4444}
4545const 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) => {
139168type SchemaFrameState = any
140169
141170export 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
247284const mapStateToProps = ( state : GlobalState ) => ( {
248- neo4jVersion : getRawVersion ( state )
285+ neo4jVersion : getSemanticVersion ( state )
249286} )
250287
251288export default withBus ( connect ( mapStateToProps , null ) ( Frame ) )
0 commit comments