TilesView.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { HomeTile } from '../HomeTile/HomeTile';
  4. import { FlexLayout } from 'ca-ui-toolkit';
  5. import ReactHtmlParser from 'react-html-parser';
  6. import './TilesView.scss';
  7. export class TilesView extends Component {
  8. static propTypes = {
  9. /** Custom class name(s) */
  10. className: PropTypes.string,
  11. /** The glass context handed down */
  12. glassContext: PropTypes.object,
  13. /** A list of the tiles formatted properly for use from the ca-ui-toolkit */
  14. tiles: PropTypes.array,
  15. /** A list of the tiles unformatted with all information. This is to be used by glassContext */
  16. tileAssets: PropTypes.array,
  17. /** a boolean showing whether or not something can be uploaded is there is no data */
  18. allowUploadFiles: PropTypes.bool,
  19. /** An id used to remove context menus for tiles */
  20. stateId: PropTypes.string,
  21. /** A reference to the ES5 homeView object */
  22. homeView: PropTypes.object,
  23. /** A copy of the i18n object used to translate strings */
  24. stringGetter: PropTypes.object
  25. };
  26. static defaultProps = {
  27. tiles: []
  28. };
  29. state = {
  30. tiles: [],
  31. tileAssets: []
  32. };
  33. constructor(props) {
  34. super(props);
  35. }
  36. componentDidMount() {
  37. this.setState({
  38. tiles: this.props.tiles,
  39. tileAssets: this.props.tileAssets
  40. });
  41. }
  42. componentDidUpdate(prevProps) {
  43. if (prevProps.tiles.length !== this.props.tiles.length) {
  44. this.setState({
  45. tiles: this.props.tiles,
  46. tileAssets: this.props.tileAssets
  47. });
  48. } else {
  49. for (let i = 0; i < this.props.tiles.length; i++) {
  50. if (prevProps.tiles[i].label !== this.props.tiles[i].label || prevProps.tiles[i].type !== this.props.tiles[i].type ||prevProps.tiles[i].date !== this.props.tiles[i].date) {
  51. this.setState({
  52. tiles: this.props.tiles,
  53. tileAssets: this.props.tileAssets
  54. });
  55. break;
  56. }
  57. }
  58. }
  59. }
  60. render() {
  61. const { glassContext, stringGetter, homeView, stateId } = this.props;
  62. const { tiles, tileAssets } = this.state;
  63. let tileViews = tiles.map((tile, i) => {
  64. return <HomeTile key={i} content={tile} glassContext={ glassContext } asset={ tileAssets[i] } homeView={homeView} stateId={stateId} stringGetter={stringGetter} ></HomeTile>;
  65. });
  66. return(
  67. <div className="tilesViewContainer">
  68. <div className="assetTilesContainer">
  69. <FlexLayout direction="row" wrap="wrap" className="tileFlexLayout">
  70. {
  71. tileViews
  72. }
  73. </FlexLayout>
  74. </div>
  75. </div>
  76. );
  77. }
  78. }