2020
2121import neo4j from 'neo4j-driver'
2222import Rx from 'rxjs/Rx'
23+ import semver from 'semver'
2324import bolt from 'services/bolt/bolt'
2425import { isConfigValFalsy } from 'services/bolt/boltHelpers'
2526import { APP_START } from 'shared/modules/app/appDuck'
@@ -59,6 +60,7 @@ import {
5960 isACausalCluster ,
6061 setClientConfig
6162} from '../features/featuresDuck'
63+ import { clearHistory } from 'shared/modules/history/historyDuck'
6264
6365export const NAME = 'meta'
6466export const UPDATE = 'meta/UPDATE'
@@ -96,6 +98,8 @@ export function getMetaInContext(state: any, context: any) {
9698export const getVersion = ( state : any ) =>
9799 ( state [ NAME ] || { } ) . server ? ( state [ NAME ] || { } ) . server . version : 0
98100export const getEdition = ( state : any ) => state [ NAME ] . server . edition
101+ export const hasEdition = ( state : any ) =>
102+ state [ NAME ] . server . edition !== initialState . server . edition
99103export const getStoreSize = ( state : any ) => state [ NAME ] . server . storeSize
100104export const getClusterRole = ( state : any ) => state [ NAME ] . role
101105export const isEnterprise = ( state : any ) =>
@@ -106,20 +110,26 @@ export const getStoreId = (state: any) =>
106110
107111export const getAvailableSettings = ( state : any ) =>
108112 ( state [ NAME ] || initialState ) . settings
109- export const allowOutgoingConnections = ( state : any ) =>
113+ export const getAllowOutgoingConnections = ( state : any ) =>
110114 getAvailableSettings ( state ) [ 'browser.allow_outgoing_connections' ]
111115export const credentialsTimeout = ( state : any ) =>
112116 getAvailableSettings ( state ) [ 'browser.credential_timeout' ] || 0
113117export const getRemoteContentHostnameAllowlist = ( state : any ) =>
114118 getAvailableSettings ( state ) [ 'browser.remote_content_hostname_allowlist' ]
115119export const getDefaultRemoteContentHostnameAllowlist = ( _state : any ) =>
116120 initialState . settings [ 'browser.remote_content_hostname_allowlist' ]
117- export const shouldRetainConnectionCredentials = ( state : any ) => {
121+ export const getRetainConnectionCredentials = ( state : any ) => {
118122 const settings = getAvailableSettings ( state )
119123 const conf = settings [ 'browser.retain_connection_credentials' ]
120124 if ( conf === null || typeof conf === 'undefined' ) return false
121125 return ! isConfigValFalsy ( conf )
122126}
127+ export const getRetainEditorHistory = ( state : any ) => {
128+ const settings = getAvailableSettings ( state )
129+ const conf = settings [ 'browser.retain_editor_history' ]
130+ if ( conf === null || typeof conf === 'undefined' ) return false
131+ return ! isConfigValFalsy ( conf )
132+ }
123133export const getDatabases = ( state : any ) =>
124134 ( state [ NAME ] || initialState ) . databases
125135export const getActiveDbName = ( state : any ) =>
@@ -128,6 +138,24 @@ export const getActiveDbName = (state: any) =>
128138 * Helpers
129139 */
130140
141+ export const VERSION_FOR_EDITOR_HISTORY_SETTING = '4.3.0'
142+
143+ export const versionHasEditorHistorySetting = ( version : string ) =>
144+ semver . gte ( version , VERSION_FOR_EDITOR_HISTORY_SETTING )
145+
146+ export const supportsEditorHistorySetting = ( state : any ) =>
147+ isEnterprise ( state ) && versionHasEditorHistorySetting ( getVersion ( state ) )
148+
149+ export const shouldAllowOutgoingConnections = ( state : any ) =>
150+ ( hasEdition ( state ) && ! isEnterprise ( state ) ) ||
151+ getAllowOutgoingConnections ( state )
152+
153+ export const shouldRetainConnectionCredentials = ( state : any ) =>
154+ ! isEnterprise ( state ) || getRetainConnectionCredentials ( state )
155+
156+ export const shouldRetainEditorHistory = ( state : any ) =>
157+ ! supportsEditorHistorySetting ( state ) || getRetainEditorHistory ( state )
158+
131159function updateMetaForContext ( state : any , meta : any , context : any ) {
132160 if ( ! meta || ! meta . records || ! meta . records . length ) {
133161 return {
@@ -216,7 +244,8 @@ export const initialState = {
216244 settings : {
217245 'browser.allow_outgoing_connections' : false ,
218246 'browser.remote_content_hostname_allowlist' : 'guides.neo4j.com, localhost' ,
219- 'browser.retain_connection_credentials' : false
247+ 'browser.retain_connection_credentials' : false ,
248+ 'browser.retain_editor_history' : false
220249 }
221250}
222251
@@ -605,6 +634,13 @@ export const serverConfigEpic = (some$: any, store: any) =>
605634 }
606635 store . dispatch ( setRetainCredentials ( retainCredentials ) )
607636 value = retainCredentials
637+ } else if ( name === 'browser.retain_editor_history' ) {
638+ let retainHistory = true
639+ // Check if we should wipe user history from localstorage
640+ if ( typeof value !== 'undefined' && isConfigValFalsy ( value ) ) {
641+ retainHistory = false
642+ }
643+ value = retainHistory
608644 } else if ( name === 'browser.allow_outgoing_connections' ) {
609645 // Use isConfigValFalsy to cast undefined to true
610646 value = ! isConfigValFalsy ( value )
@@ -623,6 +659,10 @@ export const serverConfigEpic = (some$: any, store: any) =>
623659 updateUserCapability ( USER_CAPABILITIES . serverConfigReadable , true )
624660 )
625661 store . dispatch ( updateSettings ( settings ) )
662+ // settings must be updated in state for this check to work
663+ if ( ! shouldRetainEditorHistory ( store . getState ( ) ) ) {
664+ store . dispatch ( clearHistory ( ) )
665+ }
626666 return Rx . Observable . of ( null )
627667 } )
628668 } )
0 commit comments