2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 import React, {Component} from 'react';
27 import {connect} from 'react-redux';
28 import FontAwesome from 'react-fontawesome';
29 import Button from 'react-bootstrap/lib/Button.js';
30 import Modal from 'react-bootstrap/lib/Modal.js';
31 import GlobalAutoCompleteSearchBar from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBar.jsx';
32 import {postAnalyticsData} from 'app/analytics/AnalyticsActions.js';
33 import GlobalInlineMessageBar from 'app/GlobalInlineMessageBar/GlobalInlineMessageBar.jsx';
34 import {getClearGlobalMessageEvent} from 'app/GlobalInlineMessageBar/GlobalInlineMessageBarActions.js';
39 } from 'react-router-dom';
43 MENU_ITEM_TIER_SUPPORT,
45 } from './MainScreenWrapperConstants.js';
49 } from './MainScreenWrapperActionHelper.js';
51 import {clearSuggestionsTextField} from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarActions.js';
53 import customViews from 'resources/views/customViews.json';
55 const mapStateToProps = ({mainWrapper}) => {
58 toggleButtonActive = false
67 const mapActionsToProps = (dispatch) => {
69 onShowMenu: () => dispatch(showMainMenu(true)),
71 dispatch(showMainMenu(false));
73 dispatchAnalyticsData: () => dispatch(
74 postAnalyticsData(document.documentElement.outerHTML.replace('\s+', ''))),
75 onRouteChange: () => {
76 dispatch(getClearGlobalMessageEvent());
77 dispatch(clearSuggestionsTextField());
82 class MainScreenHeader extends Component {
84 showMenu: React.PropTypes.bool,
85 toggleButtonActive: React.PropTypes.bool
88 navigationLinkAndCurrentPathMatch(location, to) {
89 let linkPathElements = to.split('/');
90 let locationElements = location.pathname.split('/');
92 // the element arrays above will have the route at index 1 ... need to
93 // verify if the routes match
94 return locationElements[1] === linkPathElements[1];
97 hasRouteChanged(currentPath, nextPath) {
98 let currentPathParts = currentPath.split('/');
99 let nextPathParts = nextPath.split('/');
101 if (currentPathParts[1] !== nextPathParts[1]) {
108 componentWillReceiveProps(nextProps) {
109 if (this.props.location &&
110 this.props.location.pathname !== nextProps.location.pathname) {
112 this.props.dispatchAnalyticsData();
114 if (this.hasRouteChanged(this.props.location.pathname,
115 nextProps.location.pathname)) {
116 this.props.onRouteChange();
129 let menuOptions = [];
131 const MenuItem = ({label, iconClass, to}) => (
132 <Route path={to} children={({location}) => (
133 <NavLink to={to} onClick={onHideMenu}>
134 <div className={this.navigationLinkAndCurrentPathMatch(location, to) ? 'main-menu-button-active' : 'main-menu-button'}>
135 <div className={iconClass}/>
136 <div className='button-icon'>{label}</div>
142 // add Tier Support view
144 <MenuItem to='/viewInspect' label={MENU_ITEM_TIER_SUPPORT}
145 iconClass='button-icon view-inspect-button-icon'/>
149 // 2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d is
150 // the hash for 'VNFs' ... ensures VNF Search screen defaults to the
151 // aggregate VNF results
154 to='/vnfSearch/2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d'
155 label={MENU_ITEM_VNF_SEARCH}
156 iconClass='button-icon vnf-search-button-icon'/>
159 // add all custom view menu options
160 for (let view in customViews) {
162 <MenuItem to={customViews[view]['viewName']}
163 label={customViews[view]['displayName']}
164 iconClass='button-icon inventory-button-icon'/>
170 <div className='header'>
173 bsClass={(toggleButtonActive)
174 ? 'toggle-view-button-active'
175 : 'toggle-view-button'}
176 onClick={onShowMenu}>
177 <FontAwesome name='bars'/>
179 <Modal show={showMenu} onHide={onHideMenu}
180 dialogClassName='modal-main-menu'>
185 <span className='application-title'>{AAI_TITLE}</span>
186 <GlobalAutoCompleteSearchBar history={this.props.history}/>
188 <GlobalInlineMessageBar />
196 export default connect(mapStateToProps, mapActionsToProps)(MainScreenHeader);