2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 import React, {Component} from 'react';
24 import {connect} from 'react-redux';
25 import FontAwesome from 'react-fontawesome';
26 import {clearFilters} from 'filter-bar-utils';
27 import Button from 'react-bootstrap/lib/Button.js';
28 import Modal from 'react-bootstrap/lib/Modal.js';
29 import GlobalAutoCompleteSearchBar from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBar.jsx';
30 import {postAnalyticsData} from 'app/analytics/AnalyticsActions.js';
31 import GlobalInlineMessageBar from 'app/GlobalInlineMessageBar/GlobalInlineMessageBar.jsx';
32 import {getClearGlobalMessageEvent} from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions.js';
33 import {externalUrlRequest, externalMessageRequest} from 'app/contextHandler/ContextHandlerActions.js';
37 } from 'utils/GlobalConstants.js';
42 } from 'react-router-dom';
46 MENU_ITEM_TIER_SUPPORT,
48 } from './MainScreenWrapperConstants.js';
52 clearExtensibleViewData,
54 } from './MainScreenWrapperActionHelper.js';
56 import {clearSuggestionsTextField} from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarActions.js';
57 import {changeUrlAddress} from 'utils/Routes.js';
58 import extensibleViews from 'resources/views/extensibleViews.json';
61 const mapStateToProps = ({mainWrapper}) => {
64 toggleButtonActive = false,
65 externalRequestFound = {},
78 const mapActionsToProps = (dispatch) => {
80 onShowMenu: () => dispatch(showMainMenu(true)),
82 dispatch(showMainMenu(false));
84 dispatchAnalyticsData: () => dispatch(
85 postAnalyticsData(document.documentElement.outerHTML.replace('\s+', ''))),
86 onRouteChange: () => {
87 dispatch(getClearGlobalMessageEvent());
88 dispatch(clearSuggestionsTextField());
89 dispatch(clearExtensibleViewData());
90 dispatch(clearFilters(filterBarActionTypes.CLEAR_FILTERS));
91 dispatch(setSecondaryTitle(undefined));
93 onExternalUrlRequest: (urlParamString) => {
94 dispatch(externalUrlRequest(urlParamString));
96 onExternalMessageRecieved: (messageJson) => {
97 dispatch(externalMessageRequest(messageJson));
102 class MainScreenHeader extends Component {
104 showMenu: React.PropTypes.bool,
105 toggleButtonActive: React.PropTypes.bool,
106 externalRequestFound: React.PropTypes.object,
107 secondaryTitle: React.PropTypes.string
110 navigationLinkAndCurrentPathMatch(location, to) {
111 let linkPathElements = to.split('/');
112 let locationElements = location.pathname.split('/');
114 // the element arrays above will have the route at index 1 ... need to
115 // verify if the routes match
116 return locationElements[1] === linkPathElements[1];
119 hasRouteChanged(currentPath, nextPath) {
120 let currentPathParts = currentPath.split('/');
121 let nextPathParts = nextPath.split('/');
123 if (currentPathParts[1] !== nextPathParts[1]) {
129 isValidExternalURL(url) {
130 if(decodeURIComponent(url).indexOf('&') > 0 ) {
136 componentWillMount() {
137 if(this.props.match.params.externalUrl !== undefined &&
138 this.isValidExternalURL(this.props.match.params.externalUrl)) {
139 this.props.onExternalUrlRequest(this.props.match.params.externalUrl);
142 componentWillReceiveProps(nextProps) {
143 if (this.props.location &&
144 this.props.location.pathname !==
145 nextProps.location.pathname) {
147 this.props.dispatchAnalyticsData();
149 if (this.hasRouteChanged(this.props.location.pathname,
150 nextProps.location.pathname)) {
151 this.props.onRouteChange();
155 if(nextProps.match.params.externalUrl !== undefined &&
156 nextProps.match.params.externalUrl !== this.props.match.params.externalUrl &&
157 this.isValidExternalURL(nextProps.match.params.externalUrl)) {
158 this.props.onExternalUrlRequest(nextProps.match.params.externalUrl);
160 /* if the externalURL is not valid, we do not add any message as other proper
161 views will get that messages since the route will be this parameter.*/
163 if(this.props.externalRequestFound !== nextProps.externalRequestFound &&
164 nextProps.externalRequestFound !== undefined && nextProps.externalRequestFound.suggestion !== undefined) {
165 changeUrlAddress(nextProps.externalRequestFound.suggestion, nextProps.history);
169 receiveMessage(event) {
170 function isJson(str) {
178 let messageData = event.data.message;
179 if(isJson(messageData)) {
180 this.props.onExternalMessageRecieved(JSON.parse(messageData));
183 componentDidMount() {
184 window.addEventListener('message', this.receiveMessage, false);
186 componentWillUnmount() {
187 window.removeEventListener('message', this.receiveMessage);
199 let menuOptions = [];
201 const MenuItem = ({label, iconClass, to}) => (
202 <Route path={to} children={({location}) => (
203 <NavLink to={to} onClick={onHideMenu}>
204 <div className={this.navigationLinkAndCurrentPathMatch(location, to) ? 'main-menu-button-active' : 'main-menu-button'}>
205 <div className={iconClass}/>
206 <div className='button-icon'>{label}</div>
212 // add Tier Support view
214 <MenuItem key='schemaMenu' to='/schema' label={MENU_ITEM_TIER_SUPPORT}
215 iconClass='button-icon view-inspect-button-icon'/>
220 <MenuItem key='vnfSearchMenu'
222 label={MENU_ITEM_VNF_SEARCH}
223 iconClass='button-icon vnf-search-button-icon'/>
226 // add all custom view menu options
227 for (let view in extensibleViews) {
229 <MenuItem key={extensibleViews[view]['viewName'] + 'Menu'} to={'/' + extensibleViews[view]['viewName']}
230 label={extensibleViews[view]['displayName']}
231 iconClass={'button-icon ' + extensibleViews[view]['iconClass']}/>
235 let secondaryTitleClass = 'secondary-header';
236 if (secondaryTitle === undefined || secondaryTitle === '') {
237 secondaryTitleClass = secondaryTitleClass + ' hidden';
241 <div className='header'>
244 bsClass={(toggleButtonActive)
245 ? 'toggle-view-button-active'
246 : 'toggle-view-button'}
247 onClick={onShowMenu}>
248 <FontAwesome name='bars'/>
250 <Modal show={showMenu} onHide={onHideMenu}
251 dialogClassName='modal-main-menu'>
256 <span className='application-title'>{AAI_TITLE}</span>
257 <GlobalAutoCompleteSearchBar history={this.props.history}/>
259 <GlobalInlineMessageBar />
260 <div className={secondaryTitleClass}>
261 <span className='secondary-title'>{secondaryTitle}</span>
268 export default connect(mapStateToProps, mapActionsToProps)(MainScreenHeader);