import VnfSearch from './vnfSearch/VnfSearch.jsx';
import MainScreenHeader from './MainScreenHeader.jsx';
import {decryptParamsForView, changeUrlAddress} from 'utils/Routes.js';
+import {
+ getConfigurableViewConfigs,
+ setCustomRoutes
+} from 'app/configurableViews/ConfigurableViewActions.js';
import {isEmpty} from 'lodash';
-
+import {genericRequest} from 'app/networking/NetworkCalls.js';
import {
Route,
HashRouter as Router,
} from './MainScreenWrapperActionHelper.js';
import extensibleViews from 'resources/views/extensibleViews.json';
+import customComponentConfig from 'resources/views/customComponents.json';
+import { newCustomComponentsEvent } from 'app/configurableViews/ConfigurableViewActions.js';
+import {
+ getConfigurableRoutes
+} from 'app/configurableViews/ConfigurableViewManager.js';
+
+import {
+ getConfiguredComponentList
+} from 'app/configurableViews/index.js';
-const mapStateToProps = ({mainWrapper}) => {
+const mapStateToProps = ({mainWrapper, configurableViews}) => {
let {
showMenu = false,
toggleButtonActive = false,
extensibleViewNetworkCallbackData = {}
} = mainWrapper;
+ let {
+ configurableViewsConfig = {},
+ customComponents = {},
+ customRoutes = []
+ } = configurableViews;
+
return {
showMenu,
toggleButtonActive,
- extensibleViewNetworkCallbackData
+ extensibleViewNetworkCallbackData,
+ configurableViewsConfig,
+ customComponents,
+ customRoutes
};
};
},
onOverlayNetworkCallback: (apiUrl, body, viewName, curViewData, responseEventKey) => {
dispatch(overlayNetworkCallback(apiUrl, body, viewName, curViewData, responseEventKey));
+ },
+ onConfigurableViewsInitialLoad: (components) => {
+ dispatch(newCustomComponentsEvent(components));
+ },
+ onFetchCustomViews: () => {
+ dispatch(getConfigurableViewConfigs());
+ },
+ onSetCustomRoutes: (routes) => {
+ dispatch(setCustomRoutes(routes));
}
};
};
}
+ componentDidMount() {
+ // fetch custom views
+ this.props.onFetchCustomViews();
+
+ // fetch custom components
+ let components = getConfiguredComponentList(customComponentConfig);
+ this.props.onConfigurableViewsInitialLoad(components);
+ }
+
+ componentDidUpdate(prevProps) {
+ if ((Object.keys(this.props.customComponents).length > 0 &&
+ Object.keys(this.props.configurableViewsConfig).length > 0) &&
+ ((JSON.stringify(prevProps.configurableViewsConfig) !== JSON.stringify(this.props.configurableViewsConfig)) ||
+ (JSON.stringify(prevProps.customComponents) !== JSON.stringify(this.props.customComponents)))) {
+ // we have both config and components populated and one was just set
+ let customRoutes = getConfigurableRoutes(this.props.configurableViewsConfig, this.props.customComponents);
+ this.props.onSetCustomRoutes(customRoutes);
+ }
+ }
render() {
onExtensibleViewNetworkCallback,
extensibleViewNetworkCallbackData,
onExtensibleViewMessageCallback,
- onOverlayNetworkCallback
+ onOverlayNetworkCallback,
+ configurableViewsConfig,
+ customComponents,
+ customRoutes
} = this.props;
let customViewList = [];
extensibleViews.forEach(function(view,key) {
- let path;
- if(isEmpty(extensibleViews[key]['routePath'])){
+ let path = '', extKey = '';
+ if(isEmpty(extensibleViews[key]['viewParams'])){
path = '/' + view.viewName + '/:extensibleViewParams?';
+ extKey = view.viewName + 'Route';
} else {
- path = '/' + view.viewName + view.routePath + '/:extensibleViewParams?';
+ path = '/' + view.viewName + view.viewParams;
+ extKey = view.viewName + view.viewParams + 'Route';
}
+
var renderComponent = (props) => {
let viewParams = {};
- if(props.match.params.extensibleViewParams !== undefined) {
+ if(isEmpty(extensibleViews[key]['viewParams']) && props.match.params.extensibleViewParams !== undefined) {
viewParams = decryptParamsForView(props.match.params.extensibleViewParams);
}
changeRouteCallback = {(routeParam, historyObj) => {
changeUrlAddress(routeParam, historyObj);
}}
+ networkingCallbackPromise = {(url, relativeURL, httpMethodType) => {
+ return genericRequest(url, relativeURL, httpMethodType);
+ }}
viewName={view.displayName}
viewData={extensibleViewNetworkCallbackData}
viewParams={viewParams}/>
);
}
};
+ if(isEmpty(extensibleViews[key]['isExact']) && !extensibleViews[key]['isExact']){
+ customViewList.push(
+ <Route key={extKey} path={path} render={renderComponent}/>
+ );
+ } else {
+ customViewList.push(
+ <Route key={extKey} exact path={path} render={renderComponent}/>
+ );
+ }
- customViewList.push(
- <Route key={extensibleViews[key]['viewName'] + 'Route'} path={path}
- render={renderComponent}/>
- );
});
+ let configurableViewList = getConfigurableRoutes(configurableViewsConfig, customComponents);
+
return (
<Router>
<div className='main-app-container'>
<Route key='TierSupportRoue' path='/schema/:viParam?' component={TierSupport}/>
<Route key='VnfSearchRoute' path='/vnfSearch/:filters?' component={VnfSearch}/>
{customViewList}
+ {customRoutes}
+ {configurableViewList}
</div>
</Router>
);