11import { createStore , applyMiddleware , compose } from 'redux' ;
22import thunkMiddleware from 'redux-thunk' ;
3- import getLocationMiddleware from './state-url-mapping' ;
43import { createBrowserHistory } from 'history' ;
54import { listenForHistoryChange } from 'redux-location-state' ;
65
6+ import { getUrlData } from './getUrlData' ;
7+ import getLocationMiddleware from './state-url-mapping' ;
78import rootReducer from './reducers' ;
89
9- import url from 'url' ;
10-
11- export const webVersion = window . web_version ;
12-
13- export const customBackend = window . custom_backend ;
14-
15- export const getUrlData = ( href , singleClusterMode ) => {
16- if ( ! singleClusterMode ) {
17- const { backend, clusterName} = url . parse ( href , true ) . query ;
18- return {
19- basename : '/' ,
20- backend,
21- clusterName,
22- } ;
23- } else if ( customBackend ) {
24- const { backend} = url . parse ( href , true ) . query ;
25- return {
26- basename : '/' ,
27- backend : backend || window . custom_backend ,
28- } ;
29- } else {
30- const parsedPrefix = window . location . pathname . match ( / .* (? = \/ m o n i t o r i n g ) / ) || [ ] ;
31- const basenamePrefix = Boolean ( parsedPrefix . length ) && parsedPrefix [ 0 ] ;
32- const basename = [ basenamePrefix , 'monitoring' ] . filter ( Boolean ) . join ( '/' ) ;
33-
34- return {
35- basename,
36- backend : basenamePrefix || '' ,
37- } ;
38- }
39- } ;
10+ export let backend , basename , clusterName ;
4011
4112const composeEnhancers = window . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose ;
4213
43- export let backend , basename , clusterName ;
44-
4514function _configureStore ( aRootReducer , history , singleClusterMode ) {
4615 const { locationMiddleware, reducersWithLocation} = getLocationMiddleware ( history , aRootReducer ) ;
4716 const middlewares = applyMiddleware ( thunkMiddleware , locationMiddleware ) ;
@@ -51,11 +20,16 @@ function _configureStore(aRootReducer, history, singleClusterMode) {
5120 } ) ;
5221}
5322
54- export default function configureStore ( aRootReducer = rootReducer , singleClusterMode = true ) {
23+ function configureStore ( aRootReducer = rootReducer , singleClusterMode = true ) {
5524 ( { backend, basename, clusterName} = getUrlData ( window . location . href , singleClusterMode ) ) ;
5625 const history = createBrowserHistory ( { basename} ) ;
5726
5827 const store = _configureStore ( aRootReducer , history , singleClusterMode ) ;
5928 listenForHistoryChange ( store , history ) ;
6029 return { history, store} ;
6130}
31+
32+ export const webVersion = window . web_version ;
33+ export const customBackend = window . custom_backend ;
34+
35+ export default configureStore ;
0 commit comments