2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 import React, {Component} from 'react';
22 import {connect} from 'react-redux';
23 import * as Extensibility from './extensibility/index.js';
24 import TierSupport from './tierSupport/TierSupport.jsx';
25 import VnfSearch from './vnfSearch/VnfSearch.jsx';
26 import MainScreenHeader from './MainScreenHeader.jsx';
27 import {decryptParamsForView, changeUrlAddress} from 'utils/Routes.js';
29 getConfigurableViewConfigs,
31 } from 'app/configurableViews/ConfigurableViewActions.js';
32 import {isEmpty} from 'lodash';
33 import {genericRequest} from 'app/networking/NetworkCalls.js';
39 } from 'react-router-dom';
43 extensibleViewNetworkCallback,
44 overlayNetworkCallback,
45 extensibleViewMessageCallback
46 } from './MainScreenWrapperActionHelper.js';
48 import extensibleViews from 'resources/views/extensibleViews.json';
49 import customComponentConfig from 'resources/views/customComponents.json';
50 import { newCustomComponentsEvent } from 'app/configurableViews/ConfigurableViewActions.js';
53 } from 'app/configurableViews/ConfigurableViewManager.js';
56 getConfiguredComponentList
57 } from 'app/configurableViews/index.js';
59 const mapStateToProps = ({mainWrapper, configurableViews}) => {
62 toggleButtonActive = false,
63 extensibleViewNetworkCallbackData = {}
67 configurableViewsConfig = {},
68 customComponents = {},
70 } = configurableViews;
75 extensibleViewNetworkCallbackData,
76 configurableViewsConfig,
82 const mapActionsToProps = (dispatch) => {
84 onWindowSizeChange: () => dispatch(windowResize()),
85 onExtensibleViewNetworkCallback: (apiUrl,body,viewName,curViewData) => {
86 dispatch(extensibleViewNetworkCallback(apiUrl,body,viewName,curViewData));
88 onExtensibleViewMessageCallback: (message, messageSevirity) => {
89 dispatch(extensibleViewMessageCallback(message, messageSevirity));
91 onOverlayNetworkCallback: (apiUrl, body, viewName, curViewData, responseEventKey) => {
92 dispatch(overlayNetworkCallback(apiUrl, body, viewName, curViewData, responseEventKey));
94 onConfigurableViewsInitialLoad: (components) => {
95 dispatch(newCustomComponentsEvent(components));
97 onFetchCustomViews: () => {
98 dispatch(getConfigurableViewConfigs());
100 onSetCustomRoutes: (routes) => {
101 dispatch(setCustomRoutes(routes));
106 class MainScreenWrapper extends Component {
110 window.addEventListener('resize', () => {
111 this.props.onWindowSizeChange();
116 componentDidMount() {
117 // fetch custom views
118 this.props.onFetchCustomViews();
120 // fetch custom components
121 let components = getConfiguredComponentList(customComponentConfig);
122 this.props.onConfigurableViewsInitialLoad(components);
125 componentDidUpdate(prevProps) {
126 if ((Object.keys(this.props.customComponents).length > 0 &&
127 Object.keys(this.props.configurableViewsConfig).length > 0) &&
128 ((JSON.stringify(prevProps.configurableViewsConfig) !== JSON.stringify(this.props.configurableViewsConfig)) ||
129 (JSON.stringify(prevProps.customComponents) !== JSON.stringify(this.props.customComponents)))) {
130 // we have both config and components populated and one was just set
131 let customRoutes = getConfigurableRoutes(this.props.configurableViewsConfig, this.props.customComponents);
132 this.props.onSetCustomRoutes(customRoutes);
139 onExtensibleViewNetworkCallback,
140 extensibleViewNetworkCallbackData,
141 onExtensibleViewMessageCallback,
142 onOverlayNetworkCallback,
143 configurableViewsConfig,
148 let customViewList = [];
149 extensibleViews.forEach(function(view,key) {
151 let path = '', extKey = '';
152 if(isEmpty(extensibleViews[key]['viewParams'])){
153 path = '/' + view.viewName + '/:extensibleViewParams?';
154 extKey = view.viewName + 'Route';
156 path = '/' + view.viewName + view.viewParams;
157 extKey = view.viewName + view.viewParams + 'Route';
160 var renderComponent = (props) => {
162 if(isEmpty(extensibleViews[key]['viewParams']) && props.match.params.extensibleViewParams !== undefined) {
163 viewParams = decryptParamsForView(props.match.params.extensibleViewParams);
166 if (Extensibility.default.hasOwnProperty(view.componentName)) {
167 let Component = Extensibility.default[view.componentName];
171 networkingCallback={(apiUrl, body, paramName, curViewData) => {
172 onExtensibleViewNetworkCallback(apiUrl, body, paramName, curViewData);
174 overlayCallback={(apiUrl, body, paramName, curOverlayData,responseEventKey) => {
175 onOverlayNetworkCallback(apiUrl, body, paramName, curOverlayData, responseEventKey);
177 messagingCallback ={(message, messageSeverity) => {
178 onExtensibleViewMessageCallback(message, messageSeverity);
180 changeRouteCallback = {(routeParam, historyObj) => {
181 changeUrlAddress(routeParam, historyObj);
183 networkingCallbackPromise = {(url, relativeURL, httpMethodType) => {
184 return genericRequest(url, relativeURL, httpMethodType);
186 viewName={view.displayName}
187 viewData={extensibleViewNetworkCallbackData}
188 viewParams={viewParams}/>
192 if(isEmpty(extensibleViews[key]['isExact']) && !extensibleViews[key]['isExact']){
194 <Route key={extKey} path={path} render={renderComponent}/>
198 <Route key={extKey} exact path={path} render={renderComponent}/>
204 let configurableViewList = getConfigurableRoutes(configurableViewsConfig, customComponents);
208 <div className='main-app-container'>
210 <Redirect from='/' exact to='/schema'/>
212 <Route key='MainScreenHeaderRoute' path='/:externalUrl?' component={MainScreenHeader}/>
213 <Route key='TierSupportRoue' path='/schema/:viParam?' component={TierSupport}/>
214 <Route key='VnfSearchRoute' path='/vnfSearch/:filters?' component={VnfSearch}/>
217 {configurableViewList}
224 export default connect(mapStateToProps, mapActionsToProps)(MainScreenWrapper);