import React, { Component } from 'react'; import PropTypes from 'prop-types'; import ReactHtmlParser from 'react-html-parser'; import './WelcomeView.scss'; import bg from '../../../../../images/HomeIllustration.png'; import howto_icon from '../../../../../images/home_howto-48.svg'; import samples_icon from '../../../../../images/home_samples-48.svg'; import tutorial_icon from '../../../../../images/home_tutorial-48.svg'; import accelerator_icon from '../../../../../images/home_accelerator-48.svg'; import ca_logoicon from '../../../../../images/ca_logoicon.png'; import { StartVideoModal } from '../StartVideoModal/StartVideoModal'; import { SampleModal } from '../SampleModal/SampleModal'; import { WelcomeTile } from '../WelcomeTile/WelcomeTile'; export class WelcomeView extends Component { static propTypes = { /** Custom class name(s) */ className: PropTypes.string, /** A copy of the i18n translation object */ stringGetter: PropTypes.object, /** Used as welcome message (primary & secondary) object, consisting of user and slogan*/ labels: PropTypes.object.isRequired, /** A copy of the glass context */ glassContext: PropTypes.object, /** The helper to open the sample folder in the side nav-bar */ sampleOpener: PropTypes.func, /** The theme values from glass */ themeValues: PropTypes.object, /** The helper to check if the sample folder is installed in the side nav-bar */ sampleChecker: PropTypes.func }; state = { openVideoModal: false, openSampleModal: false, sampleInstalled: false, openSocialModal: false }; constructor(props) { super(props); } componentDidMount(){ this.sampleFolderChecker(); } sampleFolderChecker(){ this.props.sampleChecker().then(status => { if(status !== this.state.sampleInstalled){ this.setState({ sampleInstalled: status }); } }); } // Reformat the primary title to a DOM node by enforcing a new-line for brand name titleFormatter(){ const { stringGetter, labels } = this.props; let primaryTitleArray = stringGetter.get('welcome_primary_title', { 'brandName': labels.brand }).split(' '); if(labels.brand.includes('IBM')){ primaryTitleArray.splice(primaryTitleArray.indexOf('IBM'), 0, '
'); } else{ primaryTitleArray.splice(primaryTitleArray.indexOf('Cognos'), 0, '
'); } return ReactHtmlParser(primaryTitleArray.join(' ')); } // Formatting of Product brand brandNameFormatter(){ const { labels } = this.props; return ReactHtmlParser(labels.brand); } // Instrumentation service binded on the tile of tour _sendInstrumentationEvtTour(context){ var instrumentationService = context.getCoreSvc('.Instrumentation'); var options = { action: 'clicked', uiElement: 'tour_tile' }; if (instrumentationService.enabled) { instrumentationService.track({ type: 'CTA Clicked', action: options.action, uiElement: options.uiElement, milestoneName: options.action + '_ui_element_' + options.uiElement, CTA: 'Take a Quick Tour' }); } } // Instrumentation service binded on the tile for video modal _sendInstrumentationEvtVideo(context){ var instrumentationService = context.getCoreSvc('.Instrumentation'); var options = { action: 'clicked', uiElement: 'video_tile' }; if (instrumentationService.enabled) { instrumentationService.track({ type: 'CTA Clicked', action: options.action, uiElement: options.uiElement, milestoneName: options.action + '_ui_element_' + options.uiElement, CTA: 'Watch How-to Videos' }); } } // Instrumentation service binded on the tile for sample modal _sendInstrumentationEvtSample(context){ var instrumentationService = context.getCoreSvc('.Instrumentation'); var options = { action: 'clicked', uiElement: 'sample_tile' }; if (instrumentationService.enabled) { instrumentationService.track({ type: 'CTA Clicked', action: options.action, uiElement: options.uiElement, milestoneName: options.action + '_ui_element_' + options.uiElement, CTA: 'Visit Samples' }); } } // Instrumentation service binded on the tile for accelerator catalogue _sendInstrumentationEvtAccelerator(context){ var instrumentationService = context.getCoreSvc('.Instrumentation'); var options = { action: 'clicked', uiElement: 'accelerator_tile' }; if (instrumentationService.enabled) { instrumentationService.track({ type: 'CTA Clicked', action: options.action, uiElement: options.uiElement, milestoneName: options.action + '_ui_element_' + options.uiElement, CTA: 'Browse Accelerator Catalog' }); } } // Check the status whether instrumentation service is enabled _isInstrumentationEnabled(context){ let instrumentationService = context.getCoreSvc('.Instrumentation'); return instrumentationService.enabled; } // Handler to open the modal via tabbing action - type: video, sample _openModalViaTabbing(e, type){ e.stopPropagation(); // If not a shift click, ctrl click or a right click or the user pressed enter on the context menu if((e.type == 'click' && !e.shiftKey && !e.ctrlKey && e.nativeEvent.which !== 3) || (e.type=='keyup' && e.keyCode === 13)) { e.persist(); if(type==='video'){ this._openVideoModal(); this._sendInstrumentationEvtVideo(this.props.glassContext); } else if(type==='sample'){ this._openSampleModal(); this._sendInstrumentationEvtSample(this.props.glassContext); } else if(type==='tour'){ this._sendInstrumentationEvtTour(this.props.glassContext); } else if(type==='accelerator') { this._openAcceleratorCatalogue(); this._sendInstrumentationEvtAccelerator(this.props.glassContext); } } } // Handler to close the video modal _closeVideoModal(){ this.setState({ openVideoModal: false }); } // Handler to open the video modal _openVideoModal(){ this.setState({ openVideoModal: true }); } // Handler to close the sample modal _closeSampleModal(){ this.setState({ openSampleModal: false }); } // Handler to open the sample modal _openSampleModal(){ this.setState({ openSampleModal: true }); } // Handler to close the social insights modal _closeSocialModal(){ this.setState({ openSocialModal: false }); } // Handler to open the accelerator catalogue _openAcceleratorCatalogue() { const link = 'https://community.ibm.com/accelerators/?context=analytics&product=Cognos%20Analytics'; window.open(link, '_blank'); } _isSampleInstalled() { return this.state.sampleInstalled; } render() { const { stringGetter, glassContext, sampleOpener, themeValues } = this.props; const brandLogo = themeValues.images.brandIcon==='common-CA_Avatar_Colour_64' ? {themeValues.images.altText} : {themeValues.images.altText}; const tourTile = this._isInstrumentationEnabled(glassContext) && this._isSampleInstalled() ? this._openModalViaTabbing(e, 'tour')} onClick={() => {this._sendInstrumentationEvtTour(glassContext);}} isLast={false} /> : null; const howTile = this._openModalViaTabbing(e, 'video')} onClick={() => {this._openVideoModal(); this._sendInstrumentationEvtVideo(glassContext);} } isLast={false} />; const sampleTile = this.state.sampleInstalled ? this._openModalViaTabbing(e, 'sample')} onClick={() => {this._openSampleModal(); this._sendInstrumentationEvtSample(glassContext);}} isLast={false} /> : null; const acceleratorTile = this._openModalViaTabbing(e, 'accelerator')} onClick={() => {this._openAcceleratorCatalogue(); this._sendInstrumentationEvtAccelerator(glassContext);} } isLast={true} />; return (
{ this.state.openVideoModal && ( this._closeVideoModal()}/>) } { this.state.openSampleModal && ( this._closeSampleModal()}/>) }
{brandLogo}
{this.titleFormatter()}
{ stringGetter.get('welcome_secondary_title') }
{tourTile} {howTile} {sampleTile} {acceleratorTile}
); } }