/* * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. * Copyright © 2017-2018 Amdocs * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= */ import React, {Component} from 'react'; import {connect} from 'react-redux'; import * as Extensibility from './extensibility/index.js'; import TierSupport from './tierSupport/TierSupport.jsx'; import VnfSearch from './vnfSearch/VnfSearch.jsx'; import MainScreenHeader from './MainScreenHeader.jsx'; import {decryptParamsForView, changeUrlAddress} from 'utils/Routes.js'; import {isEmpty} from 'lodash'; import {genericRequest} from 'app/networking/NetworkCalls.js'; import { Route, HashRouter as Router, Switch, Redirect } from 'react-router-dom'; import { windowResize, extensibleViewNetworkCallback, overlayNetworkCallback, extensibleViewMessageCallback } from './MainScreenWrapperActionHelper.js'; import extensibleViews from 'resources/views/extensibleViews.json'; const mapStateToProps = ({mainWrapper}) => { let { showMenu = false, toggleButtonActive = false, extensibleViewNetworkCallbackData = {} } = mainWrapper; return { showMenu, toggleButtonActive, extensibleViewNetworkCallbackData }; }; const mapActionsToProps = (dispatch) => { return { onWindowSizeChange: () => dispatch(windowResize()), onExtensibleViewNetworkCallback: (apiUrl,body,viewName,curViewData) => { dispatch(extensibleViewNetworkCallback(apiUrl,body,viewName,curViewData)); }, onExtensibleViewMessageCallback: (message, messageSevirity) => { dispatch(extensibleViewMessageCallback(message, messageSevirity)); }, onOverlayNetworkCallback: (apiUrl, body, viewName, curViewData, responseEventKey) => { dispatch(overlayNetworkCallback(apiUrl, body, viewName, curViewData, responseEventKey)); } }; }; class MainScreenWrapper extends Component { constructor() { super(); window.addEventListener('resize', () => { this.props.onWindowSizeChange(); }); } render() { const { onExtensibleViewNetworkCallback, extensibleViewNetworkCallbackData, onExtensibleViewMessageCallback, onOverlayNetworkCallback } = this.props; let customViewList = []; extensibleViews.forEach(function(view,key) { let path = '', extKey = ''; if(isEmpty(extensibleViews[key]['viewParams'])){ path = '/' + view.viewName + '/:extensibleViewParams?'; extKey = view.viewName + 'Route'; } else { path = '/' + view.viewName + view.viewParams; extKey = view.viewName + view.viewParams + 'Route'; } var renderComponent = (props) => { let viewParams = {}; if(isEmpty(extensibleViews[key]['viewParams']) && props.match.params.extensibleViewParams !== undefined) { viewParams = decryptParamsForView(props.match.params.extensibleViewParams); } if (Extensibility.default.hasOwnProperty(view.componentName)) { let Component = Extensibility.default[view.componentName]; return ( { onExtensibleViewNetworkCallback(apiUrl, body, paramName, curViewData); }} overlayCallback={(apiUrl, body, paramName, curOverlayData,responseEventKey) => { onOverlayNetworkCallback(apiUrl, body, paramName, curOverlayData, responseEventKey); }} messagingCallback ={(message, messageSeverity) => { onExtensibleViewMessageCallback(message, messageSeverity); }} 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( ); } else { customViewList.push( ); } }); return (
{customViewList}
); } } export default connect(mapStateToProps, mapActionsToProps)(MainScreenWrapper);