HomeTile.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React, { Component } from 'react';
  2. import { Tile } from 'ca-ui-toolkit';
  3. import './HomeTile.scss';
  4. import PropTypes from 'prop-types';
  5. import { SVGIcon, Tooltip } from 'ca-ui-toolkit';
  6. import menuOverflow16 from '@ba-ui-toolkit/ba-graphics/dist/icons/overflow-menu--horizontal_16.svg';
  7. export class HomeTile extends Component {
  8. static propTypes = {
  9. /** Custom class name(s) */
  10. className: PropTypes.string,
  11. /** An array of all of the tiles, if there are no assets it defaults to empty */
  12. content: PropTypes.object,
  13. /** A copy of the es5 homeview object */
  14. homeView: PropTypes.object,
  15. /** An object representing the glass context */
  16. glassContext: PropTypes.object,
  17. /** An Id used to remove context menus when clicked away */
  18. stateId: PropTypes.string,
  19. /** An unformatted object representing all information about the Tile */
  20. asset: PropTypes.object,
  21. /** An object that is used to translate all strings */
  22. stringGetter: PropTypes.object
  23. };
  24. constructor(props) {
  25. super(props);
  26. this.tileContainer = React.createRef();
  27. this.state = {
  28. menuLoading: false
  29. };
  30. }
  31. /**
  32. * This function is triggered when a user either clicks on the three dots in the corner of the menu or
  33. * when a user tabs to focus on the three dots and presses enter.
  34. */
  35. _onMenu(e) {
  36. e.stopPropagation();
  37. // If not a shift click, ctrl click or a right click or the user pressed enter on the context menu
  38. if((e.type == 'click' && !e.shiftKey && !e.ctrlKey && e.nativeEvent.which !== 3) || (e.type=='keyup' && e.keyCode === 13)) {
  39. this.setState({ menuLoading: true });
  40. e.persist();
  41. const { homeView, asset } = this.props;
  42. if(homeView && homeView.requiresAssetVerification) {
  43. homeView.loadAssetContextMenu(asset, e).then(function() {
  44. this.setState({ menuLoading: false });
  45. }.bind(this));
  46. }
  47. }
  48. }
  49. _openTile(event) {
  50. if(event.type === 'click' || (event.type === 'keyup' && event.keyCode === 13)) {
  51. this.props.homeView.onTileClick(this.props.asset);
  52. }
  53. }
  54. _getEllipsisIcon() {
  55. const { menuLoading } = this.state;
  56. const className = menuLoading ? 'contextMenuButton contextMenuButton_active' : 'contextMenuButton';
  57. return (
  58. <div role="menu" tabIndex='0' className="iconWrapper" onKeyUp={ (e) => { this._onMenu(e); }}>
  59. <Tooltip orient="right" delay>
  60. <SVGIcon iconId={menuOverflow16.id} rotate={90} className={className} onClick={(e) => { this._onMenu(e); }}/>
  61. </Tooltip>
  62. </div>
  63. );
  64. }
  65. render() {
  66. const { content, className, stringGetter, asset, glassContext } = this.props;
  67. const fullClassName = className ? `${className} caHomeTile` : 'caHomeTile';
  68. content.type = content.type ? content.type[0].toUpperCase() + content.type.slice(1).toLowerCase() : '';
  69. let textDir = 'auto';
  70. if (glassContext && glassContext.services && glassContext.services.userProfile && glassContext.services.userProfile.preferences && glassContext.services.userProfile.preferences.biDirectionalFeaturesEnabled){
  71. textDir = glassContext.services.userProfile.preferences.baseTextDirection.toLowerCase();
  72. }
  73. /**
  74. * dashboard/report/story => purple tags
  75. * exploration/notebooks = blue tags
  76. * data upload, data sets, data module, data = green tags
  77. * others = grey tags
  78. */
  79. if(asset.type === 'report' || asset.type === 'reportView' || asset.type === 'interactiveReport' || asset.type === 'powerPlay8Report' || (asset.type === 'exploration' && (!asset.tags || asset.tags[0] !== 'explore'))){
  80. content.color = 'purple';
  81. }else if((asset.type === 'exploration' && asset.tags && asset.tags[0] === 'explore') || asset.type === 'jupyterNotebook'){
  82. content.color = 'blue';
  83. }else if(asset.type === 'dataSet2' || asset.type === 'module' || asset.type === 'uploadedFile' || asset.type === 'URL'){
  84. content.color = 'teal';
  85. // If it's data and only one word, make all lowercased according to design doc
  86. content.type = content.type && content.type.split(' ').length === 1? content.type.toLowerCase() : content.type;
  87. }else{
  88. content.color = 'gray';
  89. }
  90. return (
  91. <div className={fullClassName} ref={this.tileContainer}>
  92. <Tile size='large' key={content.label} textDir={textDir} dateLabel={stringGetter.get('list_header_last_modified')} content={content} onClick={ this._openTile.bind(this) } onKeyUp={ this._openTile.bind(this) } ellipsisIcon={this._getEllipsisIcon()} ellipsisTooltipLabel={stringGetter.get('assetActionMenu')}></Tile>
  93. </div>
  94. );
  95. }
  96. }