import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { SVGIcon } from 'ca-ui-toolkit'; import ReactHtmlParser from 'react-html-parser'; import './QuickLaunch.scss'; import { QuickLaunchTarget } from '../QuickLaunchTarget/QuickLaunchTarget'; export class QuickLaunch extends Component{ static propTypes = { /** Custom class name(s) */ className: PropTypes.string, /** Show the quick launch options if set to true */ showQuickLaunch: PropTypes.bool, /** A copy of the i18n object for translating strings */ stringGetter: PropTypes.object, /** A name showing what folder to upload the file to */ folderName: PropTypes.string, /** A list of the possible items that the uploaded file can become */ quickLaunchCollectionId: PropTypes.string, /** A reference to the ES5 homeView object */ homeView: PropTypes.object, /** A copy of the glass context */ glassContext: PropTypes.object, /** Hides the quick launch when called */ hideQuickLaunch: PropTypes.func, /** Specifies if a jupyter server is configured */ jupyterEnabled: PropTypes.string }; constructor(props) { super(props); this.state = { uploadText: this.props.stringGetter.get('uploadToFolder', { folderName: props.folderName || props.stringGetter.get('myContent'), launchAction: '' }), quickLaunchItems: [] }; /** * Retrieve the possible quick launch items from glass to be displayed in the quick launch */ if (props.glassContext) { props.glassContext.appController.findCollection(props.quickLaunchCollectionId) .then(function (itemCollection) { // check if the jupyter server has been configured, otherwise disable the jupyter notebook quicklaunch tile // jupyter is not configured if the config is an empty string if (props.jupyterEnabled === ''){ itemCollection = itemCollection.filter((item) => { return item.targetId !== 'jupyterNotebook'; }); } this.setState({ quickLaunchItems: itemCollection || [] }); }.bind(this)); } } setUploadBannerText(launchAction) { const { stringGetter, folderName } = this.props; const msgKey = (launchAction) ? 'uploadAndLaunch' : 'uploadToFolder'; const message = stringGetter.get(msgKey, { folderName: folderName || stringGetter.get('myContent'), launchAction: launchAction || '' }); this.setState({ uploadText: message }); } render() { const { showQuickLaunch, stringGetter, glassContext, homeView, hideQuickLaunch } = this.props; const { quickLaunchItems } = this.state; const quickLaunchTargets = quickLaunchItems.map((item, i) => { return ; }); if (showQuickLaunch) { return (
{ ReactHtmlParser(this.state.uploadText) }
{ stringGetter.get('quickLaunch') }
{ ReactHtmlParser(stringGetter.get('uploadAndLaunch', { folderName: this.props.folderName || stringGetter.get('myContent'), launchAction: '' })) }
{ quickLaunchTargets }
); } else { return (
); } } }