@@ -21,7 +21,9 @@ import { versionHasEditorHistorySetting } from './utils'
2121import { isConfigValFalsy } from 'services/bolt/boltHelpers'
2222import { GlobalState } from 'shared/globalState'
2323import { APP_START } from 'shared/modules/app/appDuck'
24+ import { extractServerInfo } from './utils'
2425import { coerce , SemVer } from 'semver'
26+ import { gte } from 'lodash-es'
2527
2628export const UPDATE_META = 'meta/UPDATE_META'
2729export const PARSE_META = 'meta/PARSE_META'
@@ -33,6 +35,7 @@ export const DB_META_DONE = 'meta/DB_META_DONE'
3335
3436export const SYSTEM_DB = 'system'
3537export const VERSION_FOR_EDITOR_HISTORY_SETTING = '4.3.0'
38+ export const VERSION_FOR_CLUSTER_ROLE_IN_SHOW_DB = '4.3.0'
3639
3740export const metaQuery = `
3841CALL db.labels() YIELD label
@@ -51,7 +54,6 @@ MATCH ()-[]->() RETURN { name:'relationships', data: count(*)} AS result
5154
5255export const serverInfoQuery =
5356 'CALL dbms.components() YIELD name, versions, edition'
54- import { extractServerInfo } from './utils'
5557
5658export function fetchMetaData ( ) {
5759 return {
@@ -97,7 +99,7 @@ export const initialState = {
9799 properties : [ ] ,
98100 functions : [ ] ,
99101 procedures : [ ] ,
100- role : null ,
102+ role : null , // Used pre version 4.3 (before SHOW DATABASES had the role and we had to query for it)
101103 server : {
102104 version : null ,
103105 edition : null ,
@@ -162,7 +164,6 @@ export const getEdition = (state: GlobalState) => state[NAME].server.edition
162164export const hasEdition = ( state : any ) =>
163165 state [ NAME ] . server . edition !== initialState . server . edition
164166export const getStoreSize = ( state : any ) => state [ NAME ] . server . storeSize
165- export const getClusterRole = ( state : any ) => state [ NAME ] . role
166167export const isEnterprise = ( state : any ) =>
167168 [ 'enterprise' ] . includes ( state [ NAME ] . server . edition )
168169export const isBeta = ( state : any ) => / - / . test ( state [ NAME ] . server . version )
@@ -219,6 +220,28 @@ export const shouldRetainConnectionCredentials = (state: any) =>
219220export const shouldRetainEditorHistory = ( state : any ) =>
220221 ! supportsEditorHistorySetting ( state ) || getRetainEditorHistory ( state )
221222
223+ export const isOnCausalCluster = ( state : GlobalState ) : boolean => {
224+ const version = getSemanticVersion ( state )
225+ if ( ! version ) return false
226+
227+ if ( gte ( version , VERSION_FOR_CLUSTER_ROLE_IN_SHOW_DB ) ) {
228+ return getDatabases ( state ) . some ( database => database . role !== 'standalone' )
229+ } else {
230+ return hasProcedure ( state , 'dbms.cluster.overview' )
231+ }
232+ }
233+ export const getClusterRoleForDb = ( state : GlobalState , activeDb : string ) => {
234+ const version = getSemanticVersion ( state )
235+ if ( ! version ) return false
236+
237+ if ( gte ( version , VERSION_FOR_CLUSTER_ROLE_IN_SHOW_DB ) ) {
238+ return getDatabases ( state ) . find ( database => database . name === activeDb )
239+ ?. role
240+ } else {
241+ return state [ NAME ] . role
242+ }
243+ }
244+
222245// Reducers
223246const dbMetaReducer = (
224247 state = initialState ,
0 commit comments