CustomVisualsContentComponent.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /**
  6. * Licensed Materials - Property of IBM
  7. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define(['react', 'prop-types', './CustomVisualItems', './NoCustomVisuals', '../util/CustomUtil'], function (React, PropTypes, CustomVisualItems, NoCustomVisuals, CustomUtil) {
  11. var Component = React.Component;
  12. var CONTENT_CLASS = 'vis-custom-vis-content';
  13. var CustomVisualsContentComponent = function (_Component) {
  14. _inherits(CustomVisualsContentComponent, _Component);
  15. function CustomVisualsContentComponent(props) {
  16. _classCallCheck(this, CustomVisualsContentComponent);
  17. var _this = _possibleConstructorReturn(this, _Component.call(this, props));
  18. var customVisAction = _this.props.customVisAction;
  19. customVisAction.setCustomVisualsContentComponent(_this);
  20. _this.state = {
  21. items: _this.props.items,
  22. isRefreshing: _this.props.isRefreshing
  23. };
  24. return _this;
  25. }
  26. CustomVisualsContentComponent.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  27. this.setState({
  28. items: nextProps.items,
  29. isRefreshing: nextProps.isRefreshing
  30. });
  31. };
  32. CustomVisualsContentComponent.prototype.render = function render() {
  33. var _state = this.state,
  34. items = _state.items,
  35. isRefreshing = _state.isRefreshing;
  36. var _props = this.props,
  37. handlers = _props.handlers,
  38. customVisAction = _props.customVisAction;
  39. var hasItems = items.length > 0;
  40. if (isRefreshing) {
  41. return null;
  42. }
  43. return hasItems ? React.createElement(CustomVisualItems, {
  44. items: items,
  45. containerClass: CONTENT_CLASS,
  46. itemClass: 'prop-item',
  47. onContextMenuChange: this.onContextMenuChange.bind(this),
  48. handlers: handlers,
  49. customVisAction: customVisAction
  50. }) : React.createElement(NoCustomVisuals, {
  51. handlers: handlers,
  52. customVisAction: customVisAction
  53. });
  54. };
  55. CustomVisualsContentComponent.prototype.onContextMenuChange = function onContextMenuChange(itemToUpdateOrDelete, action) {
  56. var _this2 = this;
  57. if (action === 'delete') {
  58. var dashboardApi = this.props.dashboardApi;
  59. var refreshCustomVisDefinitions = this.props.handlers.refreshCustomVisDefinitions;
  60. return CustomUtil.deleteCustomVis(dashboardApi, itemToUpdateOrDelete.name, refreshCustomVisDefinitions).then(function (items) {
  61. var customVisAction = _this2.props.customVisAction;
  62. customVisAction.setItems(items);
  63. });
  64. }
  65. };
  66. return CustomVisualsContentComponent;
  67. }(Component);
  68. CustomVisualsContentComponent.propTypes = {
  69. items: PropTypes.array.isRequired,
  70. handlers: PropTypes.shape({
  71. refreshCustomVisDefinitions: PropTypes.func.isRequired
  72. }).isRequired,
  73. isRefreshing: PropTypes.bool,
  74. dashboardApi: PropTypes.object.isRequired,
  75. customVisAction: PropTypes.object.isRequired
  76. };
  77. CustomVisualsContentComponent.defaultProps = {
  78. isRefreshing: false
  79. };
  80. return CustomVisualsContentComponent;
  81. });
  82. //# sourceMappingURL=CustomVisualsContentComponent.js.map