WelcomeView.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import ReactHtmlParser from 'react-html-parser';
  4. import './WelcomeView.scss';
  5. import bg from '../../../../../images/HomeIllustration.png';
  6. import howto_icon from '../../../../../images/home_howto-48.svg';
  7. import samples_icon from '../../../../../images/home_samples-48.svg';
  8. import tutorial_icon from '../../../../../images/home_tutorial-48.svg';
  9. import accelerator_icon from '../../../../../images/home_accelerator-48.svg';
  10. import ca_logoicon from '../../../../../images/ca_logoicon.png';
  11. import { StartVideoModal } from '../StartVideoModal/StartVideoModal';
  12. import { SampleModal } from '../SampleModal/SampleModal';
  13. import { WelcomeTile } from '../WelcomeTile/WelcomeTile';
  14. export class WelcomeView extends Component {
  15. static propTypes = {
  16. /** Custom class name(s) */
  17. className: PropTypes.string,
  18. /** A copy of the i18n translation object */
  19. stringGetter: PropTypes.object,
  20. /** Used as welcome message (primary & secondary) object, consisting of user and slogan*/
  21. labels: PropTypes.object.isRequired,
  22. /** A copy of the glass context */
  23. glassContext: PropTypes.object,
  24. /** The helper to open the sample folder in the side nav-bar */
  25. sampleOpener: PropTypes.func,
  26. /** The theme values from glass */
  27. themeValues: PropTypes.object,
  28. /** The helper to check if the sample folder is installed in the side nav-bar */
  29. sampleChecker: PropTypes.func
  30. };
  31. state = {
  32. openVideoModal: false,
  33. openSampleModal: false,
  34. sampleInstalled: false,
  35. openSocialModal: false
  36. };
  37. constructor(props) {
  38. super(props);
  39. }
  40. componentDidMount(){
  41. this.sampleFolderChecker();
  42. }
  43. sampleFolderChecker(){
  44. this.props.sampleChecker().then(status => {
  45. if(status !== this.state.sampleInstalled){
  46. this.setState({
  47. sampleInstalled: status
  48. });
  49. }
  50. });
  51. }
  52. // Reformat the primary title to a DOM node by enforcing a new-line for brand name
  53. titleFormatter(){
  54. const { stringGetter, labels } = this.props;
  55. let primaryTitleArray = stringGetter.get('welcome_primary_title', {
  56. 'brandName': labels.brand
  57. }).split(' ');
  58. if(labels.brand.includes('IBM')){
  59. primaryTitleArray.splice(primaryTitleArray.indexOf('IBM'), 0, '<br />');
  60. } else{
  61. primaryTitleArray.splice(primaryTitleArray.indexOf('Cognos'), 0, '<br />');
  62. }
  63. return ReactHtmlParser(primaryTitleArray.join(' '));
  64. }
  65. // Formatting of Product brand
  66. brandNameFormatter(){
  67. const { labels } = this.props;
  68. return ReactHtmlParser(labels.brand);
  69. }
  70. // Instrumentation service binded on the tile of tour
  71. _sendInstrumentationEvtTour(context){
  72. var instrumentationService = context.getCoreSvc('.Instrumentation');
  73. var options = {
  74. action: 'clicked',
  75. uiElement: 'tour_tile'
  76. };
  77. if (instrumentationService.enabled) {
  78. instrumentationService.track({
  79. type: 'CTA Clicked',
  80. action: options.action,
  81. uiElement: options.uiElement,
  82. milestoneName: options.action + '_ui_element_' + options.uiElement,
  83. CTA: 'Take a Quick Tour'
  84. });
  85. }
  86. }
  87. // Instrumentation service binded on the tile for video modal
  88. _sendInstrumentationEvtVideo(context){
  89. var instrumentationService = context.getCoreSvc('.Instrumentation');
  90. var options = {
  91. action: 'clicked',
  92. uiElement: 'video_tile'
  93. };
  94. if (instrumentationService.enabled) {
  95. instrumentationService.track({
  96. type: 'CTA Clicked',
  97. action: options.action,
  98. uiElement: options.uiElement,
  99. milestoneName: options.action + '_ui_element_' + options.uiElement,
  100. CTA: 'Watch How-to Videos'
  101. });
  102. }
  103. }
  104. // Instrumentation service binded on the tile for sample modal
  105. _sendInstrumentationEvtSample(context){
  106. var instrumentationService = context.getCoreSvc('.Instrumentation');
  107. var options = {
  108. action: 'clicked',
  109. uiElement: 'sample_tile'
  110. };
  111. if (instrumentationService.enabled) {
  112. instrumentationService.track({
  113. type: 'CTA Clicked',
  114. action: options.action,
  115. uiElement: options.uiElement,
  116. milestoneName: options.action + '_ui_element_' + options.uiElement,
  117. CTA: 'Visit Samples'
  118. });
  119. }
  120. }
  121. // Instrumentation service binded on the tile for accelerator catalogue
  122. _sendInstrumentationEvtAccelerator(context){
  123. var instrumentationService = context.getCoreSvc('.Instrumentation');
  124. var options = {
  125. action: 'clicked',
  126. uiElement: 'accelerator_tile'
  127. };
  128. if (instrumentationService.enabled) {
  129. instrumentationService.track({
  130. type: 'CTA Clicked',
  131. action: options.action,
  132. uiElement: options.uiElement,
  133. milestoneName: options.action + '_ui_element_' + options.uiElement,
  134. CTA: 'Browse Accelerator Catalog'
  135. });
  136. }
  137. }
  138. // Check the status whether instrumentation service is enabled
  139. _isInstrumentationEnabled(context){
  140. let instrumentationService = context.getCoreSvc('.Instrumentation');
  141. return instrumentationService.enabled;
  142. }
  143. // Handler to open the modal via tabbing action - type: video, sample
  144. _openModalViaTabbing(e, type){
  145. e.stopPropagation();
  146. // If not a shift click, ctrl click or a right click or the user pressed enter on the context menu
  147. if((e.type == 'click' && !e.shiftKey && !e.ctrlKey && e.nativeEvent.which !== 3) || (e.type=='keyup' && e.keyCode === 13)) {
  148. e.persist();
  149. if(type==='video'){
  150. this._openVideoModal();
  151. this._sendInstrumentationEvtVideo(this.props.glassContext);
  152. } else if(type==='sample'){
  153. this._openSampleModal();
  154. this._sendInstrumentationEvtSample(this.props.glassContext);
  155. } else if(type==='tour'){
  156. this._sendInstrumentationEvtTour(this.props.glassContext);
  157. } else if(type==='accelerator') {
  158. this._openAcceleratorCatalogue();
  159. this._sendInstrumentationEvtAccelerator(this.props.glassContext);
  160. }
  161. }
  162. }
  163. // Handler to close the video modal
  164. _closeVideoModal(){
  165. this.setState({ openVideoModal: false });
  166. }
  167. // Handler to open the video modal
  168. _openVideoModal(){
  169. this.setState({ openVideoModal: true });
  170. }
  171. // Handler to close the sample modal
  172. _closeSampleModal(){
  173. this.setState({ openSampleModal: false });
  174. }
  175. // Handler to open the sample modal
  176. _openSampleModal(){
  177. this.setState({ openSampleModal: true });
  178. }
  179. // Handler to close the social insights modal
  180. _closeSocialModal(){
  181. this.setState({ openSocialModal: false });
  182. }
  183. // Handler to open the accelerator catalogue
  184. _openAcceleratorCatalogue() {
  185. const link = 'https://community.ibm.com/accelerators/?context=analytics&product=Cognos%20Analytics';
  186. window.open(link, '_blank');
  187. }
  188. _isSampleInstalled() {
  189. return this.state.sampleInstalled;
  190. }
  191. render() {
  192. const { stringGetter, glassContext, sampleOpener, themeValues } = this.props;
  193. const brandLogo = themeValues.images.brandIcon==='common-CA_Avatar_Colour_64' ?
  194. <img className="brandTitleIcon" src={ca_logoicon} alt={themeValues.images.altText} /> :
  195. <img className="brandTitleIcon" src={themeValues.images.brandIcon} alt={themeValues.images.altText} />;
  196. const tourTile = this._isInstrumentationEnabled(glassContext) && this._isSampleInstalled() ?
  197. <WelcomeTile
  198. className={'tourTile'}
  199. stringGetter={stringGetter}
  200. iconID={tutorial_icon.id}
  201. titleKey={'welcome_tile_title_tour'}
  202. descriptionKey={'welcome_tile_description_tour'}
  203. onKeyUp={(e) => this._openModalViaTabbing(e, 'tour')}
  204. onClick={() => {this._sendInstrumentationEvtTour(glassContext);}}
  205. isLast={false}
  206. /> : null;
  207. const howTile = <WelcomeTile
  208. className={'howTile'}
  209. stringGetter={stringGetter}
  210. iconID={howto_icon.id}
  211. titleKey={'welcome_tile_title_how'}
  212. descriptionKey={'welcome_tile_description_how'}
  213. onKeyUp={(e) => this._openModalViaTabbing(e, 'video')}
  214. onClick={() => {this._openVideoModal(); this._sendInstrumentationEvtVideo(glassContext);} }
  215. isLast={false}
  216. />;
  217. const sampleTile = this.state.sampleInstalled ? <WelcomeTile
  218. className={'sampleTile'}
  219. stringGetter={stringGetter}
  220. iconID={samples_icon.id}
  221. titleKey={'welcome_tile_title_sample'}
  222. descriptionKey={'welcome_tile_description_sample'}
  223. onKeyUp={(e) => this._openModalViaTabbing(e, 'sample')}
  224. onClick={() => {this._openSampleModal(); this._sendInstrumentationEvtSample(glassContext);}}
  225. isLast={false}
  226. /> : null;
  227. const acceleratorTile = <WelcomeTile
  228. className={'acceleratorTile'}
  229. stringGetter={stringGetter}
  230. iconID={accelerator_icon.id}
  231. titleKey={'welcome_tile_title_accelerator'}
  232. descriptionKey={'welcome_tile_description_accelerator'}
  233. onKeyUp={(e) => this._openModalViaTabbing(e, 'accelerator')}
  234. onClick={() => {this._openAcceleratorCatalogue(); this._sendInstrumentationEvtAccelerator(glassContext);} }
  235. isLast={true}
  236. />;
  237. return (<div className="welcomeViewWrapper">
  238. {
  239. this.state.openVideoModal && (<StartVideoModal stringGetter={stringGetter} sampleOpener={sampleOpener} closeHandler={() => this._closeVideoModal()}/>)
  240. }
  241. {
  242. this.state.openSampleModal && (<SampleModal sampleOpener={sampleOpener} stringGetter={stringGetter} closeHandler={() => this._closeSampleModal()}/>)
  243. }
  244. <img className='welcomeBackground' src={bg} alt=''></img>
  245. <div className="brandTitle">
  246. {brandLogo}
  247. </div>
  248. <div className="primaryTitle">
  249. {this.titleFormatter()}
  250. </div>
  251. <div className="secondaryTitle">
  252. { stringGetter.get('welcome_secondary_title') }
  253. </div>
  254. <div className="welcomeTileWrapper">
  255. {tourTile}
  256. {howTile}
  257. {sampleTile}
  258. {acceleratorTile}
  259. </div>
  260. </div>);
  261. }
  262. }