QuickLaunch.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { SVGIcon } from 'ca-ui-toolkit';
  4. import ReactHtmlParser from 'react-html-parser';
  5. import './QuickLaunch.scss';
  6. import { QuickLaunchTarget } from '../QuickLaunchTarget/QuickLaunchTarget';
  7. export class QuickLaunch extends Component{
  8. static propTypes = {
  9. /** Custom class name(s) */
  10. className: PropTypes.string,
  11. /** Show the quick launch options if set to true */
  12. showQuickLaunch: PropTypes.bool,
  13. /** A copy of the i18n object for translating strings */
  14. stringGetter: PropTypes.object,
  15. /** A name showing what folder to upload the file to */
  16. folderName: PropTypes.string,
  17. /** A list of the possible items that the uploaded file can become */
  18. quickLaunchCollectionId: PropTypes.string,
  19. /** A reference to the ES5 homeView object */
  20. homeView: PropTypes.object,
  21. /** A copy of the glass context */
  22. glassContext: PropTypes.object,
  23. /** Hides the quick launch when called */
  24. hideQuickLaunch: PropTypes.func,
  25. /** Specifies if a jupyter server is configured */
  26. jupyterEnabled: PropTypes.string
  27. };
  28. constructor(props) {
  29. super(props);
  30. this.state = {
  31. uploadText: this.props.stringGetter.get('uploadToFolder', { folderName: props.folderName || props.stringGetter.get('myContent'), launchAction: '' }),
  32. quickLaunchItems: []
  33. };
  34. /**
  35. * Retrieve the possible quick launch items from glass to be displayed in the quick launch
  36. */
  37. if (props.glassContext) {
  38. props.glassContext.appController.findCollection(props.quickLaunchCollectionId)
  39. .then(function (itemCollection) {
  40. // check if the jupyter server has been configured, otherwise disable the jupyter notebook quicklaunch tile
  41. // jupyter is not configured if the config is an empty string
  42. if (props.jupyterEnabled === ''){
  43. itemCollection = itemCollection.filter((item) => {
  44. return item.targetId !== 'jupyterNotebook';
  45. });
  46. }
  47. this.setState({ quickLaunchItems: itemCollection || [] });
  48. }.bind(this));
  49. }
  50. }
  51. setUploadBannerText(launchAction) {
  52. const { stringGetter, folderName } = this.props;
  53. const msgKey = (launchAction) ? 'uploadAndLaunch' : 'uploadToFolder';
  54. const message = stringGetter.get(msgKey, {
  55. folderName: folderName || stringGetter.get('myContent'),
  56. launchAction: launchAction || ''
  57. });
  58. this.setState({ uploadText: message });
  59. }
  60. render() {
  61. const { showQuickLaunch, stringGetter, glassContext, homeView, hideQuickLaunch } = this.props;
  62. const { quickLaunchItems } = this.state;
  63. const quickLaunchTargets = quickLaunchItems.map((item, i) => {
  64. return <QuickLaunchTarget
  65. key={ i }
  66. content={ item }
  67. glassContext={ glassContext }
  68. setUploadText={ this.setUploadBannerText.bind(this) }
  69. homeView={homeView}
  70. hideQuickLaunch={ hideQuickLaunch }>
  71. </QuickLaunchTarget>;
  72. });
  73. if (showQuickLaunch) {
  74. return (
  75. <div className="quickLaunchContainer">
  76. <div className="uploadBanner">
  77. <SVGIcon className="uploadBannerIcon" iconId="upload_16"></SVGIcon>
  78. <span id="uploadBannerText" className="uploadBannerText">{ ReactHtmlParser(this.state.uploadText) }</span>
  79. </div>
  80. <div className="quickLaunchBanner">
  81. <div className="quickLaunchContent">
  82. <div className="quickLaunchText">
  83. <div className="quickLaunchTitle">
  84. { stringGetter.get('quickLaunch') }
  85. </div>
  86. <div className="quickLaunchDescription">
  87. { ReactHtmlParser(stringGetter.get('uploadAndLaunch', {
  88. folderName: this.props.folderName || stringGetter.get('myContent'),
  89. launchAction: ''
  90. })) }
  91. </div>
  92. </div>
  93. <div className="quickLaunchTargets">
  94. { quickLaunchTargets }
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. );
  100. } else {
  101. return (
  102. <div></div>
  103. );
  104. }
  105. }
  106. }