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,
146 let customViewList = [];
147 extensibleViews.forEach(function(view,key) {
149 let path = '', extKey = '';
150 if(isEmpty(extensibleViews[key]['viewParams'])){
151 path = '/' + view.viewName + '/:extensibleViewParams?';
152 extKey = view.viewName + 'Route';
154 path = '/' + view.viewName + view.viewParams;
155 extKey = view.viewName + view.viewParams + 'Route';
158 var renderComponent = (props) => {
160 if(isEmpty(extensibleViews[key]['viewParams']) && props.match.params.extensibleViewParams !== undefined) {
161 viewParams = decryptParamsForView(props.match.params.extensibleViewParams);
164 if (Extensibility.default.hasOwnProperty(view.componentName)) {
165 let Component = Extensibility.default[view.componentName];
169 networkingCallback={(apiUrl, body, paramName, curViewData) => {
170 onExtensibleViewNetworkCallback(apiUrl, body, paramName, curViewData);
172 overlayCallback={(apiUrl, body, paramName, curOverlayData,responseEventKey) => {
173 onOverlayNetworkCallback(apiUrl, body, paramName, curOverlayData, responseEventKey);
175 messagingCallback ={(message, messageSeverity) => {
176 onExtensibleViewMessageCallback(message, messageSeverity);
178 changeRouteCallback = {(routeParam, historyObj) => {
179 changeUrlAddress(routeParam, historyObj);
181 networkingCallbackPromise = {(url, relativeURL, httpMethodType) => {
182 return genericRequest(url, relativeURL, httpMethodType);
184 viewName={view.displayName}
185 viewData={extensibleViewNetworkCallbackData}
186 viewParams={viewParams}/>
190 if(isEmpty(extensibleViews[key]['isExact']) && !extensibleViews[key]['isExact']){
192 <Route key={extKey} path={path} render={renderComponent}/>
196 <Route key={extKey} exact path={path} render={renderComponent}/>
204 <div className='main-app-container'>
206 <Redirect from='/' exact to='/schema'/>
208 <Route key='MainScreenHeaderRoute' path='/:externalUrl?' component={MainScreenHeader}/>
209 <Route key='TierSupportRoue' path='/schema/:viParam?' component={TierSupport}/>
210 <Route key='VnfSearchRoute' path='/vnfSearch/:filters?' component={VnfSearch}/>
219 export default connect(mapStateToProps, mapActionsToProps)(MainScreenWrapper);