X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fsparky-fe.git;a=blobdiff_plain;f=src%2Fapp%2FMainScreenHeader.jsx;h=ec1efdae0bc10dbe738501dedd53cdebd8fa777a;hp=af71a973db4e7fff848db34ca43fb33303ee9afb;hb=47b85e9b95e0a0a3570f0cea4d3ee4645c911a8b;hpb=c1917730a648ddbb6cd51307cea9464a697700d8 diff --git a/src/app/MainScreenHeader.jsx b/src/app/MainScreenHeader.jsx index af71a97..ec1efda 100644 --- a/src/app/MainScreenHeader.jsx +++ b/src/app/MainScreenHeader.jsx @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs + * 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. @@ -17,18 +17,22 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ import React, {Component} from 'react'; import {connect} from 'react-redux'; import FontAwesome from 'react-fontawesome'; +import {clearFilters} from 'filter-bar-utils'; import Button from 'react-bootstrap/lib/Button.js'; import Modal from 'react-bootstrap/lib/Modal.js'; import GlobalAutoCompleteSearchBar from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBar.jsx'; import {postAnalyticsData} from 'app/analytics/AnalyticsActions.js'; -import GlobalInlineMessageBar from 'app/GlobalInlineMessageBar/GlobalInlineMessageBar.jsx'; -import {getClearGlobalMessageEvent} from 'app/GlobalInlineMessageBar/GlobalInlineMessageBarActions.js'; +import GlobalInlineMessageBar from 'app/globalInlineMessageBar/GlobalInlineMessageBar.jsx'; +import {getClearGlobalMessageEvent} from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions.js'; +import {externalUrlRequest, externalMessageRequest, getSubscriptionPayload} from 'app/contextHandler/ContextHandlerActions.js'; + +import { + filterBarActionTypes +} from 'utils/GlobalConstants.js'; import { Route, @@ -42,25 +46,37 @@ import { } from './MainScreenWrapperConstants.js'; import { - showMainMenu + showMainMenu, + clearExtensibleViewData, + setSecondaryTitle } from './MainScreenWrapperActionHelper.js'; import {clearSuggestionsTextField} from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarActions.js'; +import {changeUrlAddress} from 'utils/Routes.js'; +import extensibleViews from 'resources/views/extensibleViews.json'; -import customViews from 'resources/views/customViews.json'; const mapStateToProps = ({mainWrapper}) => { let { - showMenu = false, - toggleButtonActive = false - } = mainWrapper; + showMenu = false, + toggleButtonActive = false, + externalRequestFound = {}, + secondaryTitle = '', + subscriptionPayload = {}, + subscriptionEnabled = false + } = mainWrapper; return { showMenu, - toggleButtonActive + toggleButtonActive, + externalRequestFound, + secondaryTitle, + subscriptionPayload, + subscriptionEnabled }; }; + const mapActionsToProps = (dispatch) => { return { onShowMenu: () => dispatch(showMainMenu(true)), @@ -72,6 +88,18 @@ const mapActionsToProps = (dispatch) => { onRouteChange: () => { dispatch(getClearGlobalMessageEvent()); dispatch(clearSuggestionsTextField()); + dispatch(clearExtensibleViewData()); + dispatch(clearFilters(filterBarActionTypes.CLEAR_FILTERS)); + dispatch(setSecondaryTitle(undefined)); + }, + onExternalUrlRequest: (urlParamString) => { + dispatch(externalUrlRequest(urlParamString)); + }, + onExternalMessageRecieved: (messageJson) => { + dispatch(externalMessageRequest(messageJson)); + }, + onGetSubscriptionPayload: () => { + dispatch(getSubscriptionPayload()); } }; }; @@ -79,7 +107,10 @@ const mapActionsToProps = (dispatch) => { class MainScreenHeader extends Component { static propTypes = { showMenu: React.PropTypes.bool, - toggleButtonActive: React.PropTypes.bool + toggleButtonActive: React.PropTypes.bool, + externalRequestFound: React.PropTypes.object, + secondaryTitle: React.PropTypes.string, + subscriptionPayload: React.PropTypes.object }; navigationLinkAndCurrentPathMatch(location, to) { @@ -101,10 +132,27 @@ class MainScreenHeader extends Component { return false; } } + + isValidExternalURL(url) { + if(decodeURIComponent(url).indexOf('&') > 0 ) { + return true; + } else { + return false; + } + } + + componentWillMount() { + this.props.onGetSubscriptionPayload(); + if(this.props.match.params.externalUrl !== undefined && + this.isValidExternalURL(this.props.match.params.externalUrl)) { + this.props.onExternalUrlRequest(this.props.match.params.externalUrl); + } + } componentWillReceiveProps(nextProps) { if (this.props.location && - this.props.location.pathname !== nextProps.location.pathname) { + this.props.location.pathname !== + nextProps.location.pathname) { // update analytics this.props.dispatchAnalyticsData(); @@ -113,15 +161,80 @@ class MainScreenHeader extends Component { this.props.onRouteChange(); } } + + if(nextProps.match.params.externalUrl !== undefined && + nextProps.match.params.externalUrl !== this.props.match.params.externalUrl && + this.isValidExternalURL(nextProps.match.params.externalUrl)) { + this.props.onExternalUrlRequest(nextProps.match.params.externalUrl); + } + /* if the externalURL is not valid, we do not add any message as other proper + views will get that messages since the route will be this parameter.*/ + + if(this.props.externalRequestFound !== nextProps.externalRequestFound && + nextProps.externalRequestFound !== undefined && nextProps.externalRequestFound.suggestion !== undefined) { + changeUrlAddress(nextProps.externalRequestFound.suggestion, nextProps.history); + } + + if (nextProps.subscriptionEnabled) { + if (nextProps.subscriptionPayload !== this.props.subscriptionPayload && + Object.keys(nextProps.subscriptionPayload).length > 0) { + var getWindowUrl = function (url) { + var split = url.split('/'); + return split[0] + '//' + split[2]; + }; + window.parent.postMessage( + JSON.stringify(nextProps.subscriptionPayload), + getWindowUrl(document.referrer)); + } + } + } + + receiveMessage(event, $this) { + function isJson(str) { + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; + } + if(isJson(event.data)) { + let messageData = JSON.parse(event.data); + if(isJson(messageData.message)) { + $this.props.onExternalMessageRecieved(messageData.message); + } + } + + } + componentDidMount() { + //TODO Move this logic to the component will receive props. + //Check if the event lister is available and if the subscription is + // enabled before registering for it + if(document.referrer) { + var $this = this; + window.addEventListener('message', function (e) { + $this.receiveMessage(e, $this); + }, false); + } + } + componentWillUnmount() { + if(this.props.subscriptionEnabled) { + var $this = this; + window.removeEventListener('message', function (e) { + $this.receiveMessage(e, $this); + } + ); + } } render() { let { - showMenu, - onShowMenu, - onHideMenu, - toggleButtonActive - } = this.props; + showMenu, + onShowMenu, + onHideMenu, + toggleButtonActive, + secondaryTitle + } = this.props; let menuOptions = []; @@ -138,54 +251,56 @@ class MainScreenHeader extends Component { // add Tier Support view menuOptions.push( - ); // add VNF view - // 2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d is - // the hash for 'VNFs' ... ensures VNF Search screen defaults to the - // aggregate VNF results menuOptions.push( - ); // add all custom view menu options - for (let view in customViews) { + for (let view in extensibleViews) { menuOptions.push( - + ); } + let secondaryTitleClass = 'secondary-header'; + if (secondaryTitle === undefined || secondaryTitle === '') { + secondaryTitleClass = secondaryTitleClass + ' hidden'; + } + return ( -
-
-
- - - - {menuOptions} - - - {AAI_TITLE} - -
- +
+
+ + + + {menuOptions} + + + {AAI_TITLE} + +
+ +
+ {secondaryTitle}
- ); } }