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=856a08d8ddec4750443f1b0e18152cb006b6fdea;hb=47b85e9b95e0a0a3570f0cea4d3ee4645c911a8b;hpb=a7b4b96afee33a2ff458f906742d88cd306ed961 diff --git a/src/app/MainScreenHeader.jsx b/src/app/MainScreenHeader.jsx index 856a08d..ec1efda 100644 --- a/src/app/MainScreenHeader.jsx +++ b/src/app/MainScreenHeader.jsx @@ -1,38 +1,38 @@ /* - * ============LICENSE_START=================================================== - * SPARKY (AAI UI service) - * ============================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * All rights reserved. - * ============================================================================ + * ============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 + * 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===================================================== - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. + * ============LICENSE_END========================================================= */ - 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 GlobalInlineMessageBar from 'app/globalInlineMessageBar/GlobalInlineMessageBar.jsx'; import {getClearGlobalMessageEvent} from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions.js'; -import {externalUrlRequest, externalMessageRequest} from 'app/contextHandler/ContextHandlerActions.js'; +import {externalUrlRequest, externalMessageRequest, getSubscriptionPayload} from 'app/contextHandler/ContextHandlerActions.js'; + +import { + filterBarActionTypes +} from 'utils/GlobalConstants.js'; import { Route, @@ -54,20 +54,25 @@ import { import {clearSuggestionsTextField} from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarActions.js'; import {changeUrlAddress} from 'utils/Routes.js'; import extensibleViews from 'resources/views/extensibleViews.json'; -import {clearFilters} from 'generic-components/filterBar/FilterBarUtils.js'; + + const mapStateToProps = ({mainWrapper}) => { let { showMenu = false, toggleButtonActive = false, externalRequestFound = {}, - secondaryTitle = '' + secondaryTitle = '', + subscriptionPayload = {}, + subscriptionEnabled = false } = mainWrapper; return { showMenu, toggleButtonActive, externalRequestFound, - secondaryTitle + secondaryTitle, + subscriptionPayload, + subscriptionEnabled }; }; @@ -84,7 +89,7 @@ const mapActionsToProps = (dispatch) => { dispatch(getClearGlobalMessageEvent()); dispatch(clearSuggestionsTextField()); dispatch(clearExtensibleViewData()); - dispatch(clearFilters()); + dispatch(clearFilters(filterBarActionTypes.CLEAR_FILTERS)); dispatch(setSecondaryTitle(undefined)); }, onExternalUrlRequest: (urlParamString) => { @@ -92,6 +97,9 @@ const mapActionsToProps = (dispatch) => { }, onExternalMessageRecieved: (messageJson) => { dispatch(externalMessageRequest(messageJson)); + }, + onGetSubscriptionPayload: () => { + dispatch(getSubscriptionPayload()); } }; }; @@ -101,7 +109,8 @@ class MainScreenHeader extends Component { showMenu: React.PropTypes.bool, toggleButtonActive: React.PropTypes.bool, externalRequestFound: React.PropTypes.object, - secondaryTitle: React.PropTypes.string + secondaryTitle: React.PropTypes.string, + subscriptionPayload: React.PropTypes.object }; navigationLinkAndCurrentPathMatch(location, to) { @@ -123,6 +132,7 @@ class MainScreenHeader extends Component { return false; } } + isValidExternalURL(url) { if(decodeURIComponent(url).indexOf('&') > 0 ) { return true; @@ -130,12 +140,15 @@ class MainScreenHeader extends Component { 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 !== @@ -161,9 +174,22 @@ class MainScreenHeader extends Component { 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) { + receiveMessage(event, $this) { function isJson(str) { try { JSON.parse(str); @@ -172,16 +198,33 @@ class MainScreenHeader extends Component { } return true; } - let messageData = event.data.message; - if(isJson(messageData)) { - this.props.onExternalMessageRecieved(JSON.parse(messageData)); + if(isJson(event.data)) { + let messageData = JSON.parse(event.data); + if(isJson(messageData.message)) { + $this.props.onExternalMessageRecieved(messageData.message); + } } + } componentDidMount() { - window.addEventListener('message', this.receiveMessage, false); + //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() { - window.removeEventListener('message', this.receiveMessage); + if(this.props.subscriptionEnabled) { + var $this = this; + window.removeEventListener('message', function (e) { + $this.receiveMessage(e, $this); + } + ); + } } render() {