PreviewVisualItem.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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, 2020
  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', 'ca-ui-toolkit', '../VisualItem', '../../../widgets/livewidget/nls/StringResources', '../../../lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/information_16'], function (React, PropTypes, UI_Toolkit, VisualItem, StringResources, Information_16) {
  11. var FlexLayout = UI_Toolkit.FlexLayout,
  12. FlexItem = UI_Toolkit.FlexItem,
  13. VSpacer = UI_Toolkit.VSpacer,
  14. HSpacer = UI_Toolkit.HSpacer,
  15. Flyout = UI_Toolkit.Flyout,
  16. Label = UI_Toolkit.Label;
  17. var PreviewVisualItem = function (_VisualItem) {
  18. _inherits(PreviewVisualItem, _VisualItem);
  19. function PreviewVisualItem(props) {
  20. _classCallCheck(this, PreviewVisualItem);
  21. var _this = _possibleConstructorReturn(this, _VisualItem.call(this, props));
  22. _this.state.sdkIsRunning = false;
  23. _this._initRenderContext(_this.state.sdkIsRunning);
  24. return _this;
  25. }
  26. PreviewVisualItem.prototype._initRenderContext = function _initRenderContext(sdkIsRunning) {
  27. var item = this.state.item;
  28. var _props = this.props,
  29. handlers = _props.handlers,
  30. iconsFeature = _props.iconsFeature;
  31. var isSchematicType = handlers.isSchematicType(item);
  32. var icon = void 0;
  33. if (isSchematicType) {
  34. icon = iconsFeature.getIcon('svgFile').id;
  35. } else {
  36. icon = iconsFeature.getIcon('codeFile').id;
  37. }
  38. this._renderContext = {
  39. icon: icon,
  40. description: isSchematicType ? item.label : StringResources.get('customVisTestVisualization'),
  41. isDisabled: isSchematicType ? false : sdkIsRunning ? false : true
  42. };
  43. };
  44. PreviewVisualItem.prototype._isSDKActive = function _isSDKActive() {
  45. return this.props.handlers.isSDKActive();
  46. };
  47. PreviewVisualItem.prototype.componentDidMount = function componentDidMount() {
  48. var _this2 = this;
  49. _VisualItem.prototype.componentDidMount.call(this);
  50. return this._isSDKActive().then(function (sdkIsRunning) {
  51. if (sdkIsRunning) {
  52. _this2._initRenderContext(true);
  53. _this2.setState({
  54. sdkIsRunning: true
  55. });
  56. _this2._attachCallbacksAndImages();
  57. }
  58. }).catch(function () {
  59. // swallow it... sdk is not running and that's fine
  60. });
  61. };
  62. PreviewVisualItem.prototype.componentWillUnmount = function componentWillUnmount() {
  63. _VisualItem.prototype.componentWillUnmount.call(this);
  64. };
  65. PreviewVisualItem.prototype._getVisualItemCssClasses = function _getVisualItemCssClasses() {
  66. return _VisualItem.prototype._getVisualItemCssClasses.call(this) + ' vis-custom-preview';
  67. };
  68. PreviewVisualItem.prototype._canRenderMenuOption = function _canRenderMenuOption() {
  69. return this._renderContext.isDisabled ? true : false;
  70. };
  71. PreviewVisualItem.prototype._getContextMenuContent = function _getContextMenuContent() {
  72. return React.createElement(
  73. Flyout,
  74. {
  75. theme: true,
  76. placement: 'bottomRight',
  77. showX: true,
  78. triggerNode: this.target,
  79. domNodeToAttachTo: document.body,
  80. onClose: this.onClose.bind(this),
  81. className: 'vis-preview-indicator-menu'
  82. },
  83. React.createElement(
  84. FlexLayout,
  85. {
  86. fullHeight: true,
  87. direction: 'row',
  88. justifyContent: 'flex-start'
  89. },
  90. React.createElement(
  91. FlexItem,
  92. null,
  93. React.createElement(HSpacer, { size: 2 })
  94. ),
  95. React.createElement(
  96. FlexItem,
  97. null,
  98. React.createElement(
  99. FlexLayout,
  100. {
  101. fullHeight: true,
  102. direction: 'column',
  103. justifyContent: 'flex-start'
  104. },
  105. React.createElement(
  106. FlexItem,
  107. null,
  108. React.createElement(VSpacer, { size: 2 })
  109. ),
  110. React.createElement(
  111. FlexItem,
  112. null,
  113. React.createElement(Label, {
  114. label: StringResources.get('extVisNoSDKConnection'),
  115. className: 'vis-preview-indicator-menu-title'
  116. })
  117. ),
  118. React.createElement(
  119. FlexItem,
  120. null,
  121. React.createElement(VSpacer, { size: 2 })
  122. ),
  123. React.createElement(
  124. FlexItem,
  125. null,
  126. React.createElement(Label, {
  127. label: StringResources.get('extVisNoSDKPreviewMsg'),
  128. className: 'vis-preview-indicator-menu-msg'
  129. })
  130. ),
  131. React.createElement(
  132. FlexItem,
  133. null,
  134. React.createElement(VSpacer, { size: 2 })
  135. )
  136. )
  137. ),
  138. React.createElement(
  139. FlexItem,
  140. null,
  141. React.createElement(HSpacer, { size: 2 })
  142. )
  143. )
  144. );
  145. };
  146. return PreviewVisualItem;
  147. }(VisualItem);
  148. PreviewVisualItem.propTypes = {
  149. item: PropTypes.object.isRequired,
  150. handlers: PropTypes.shape({
  151. componentDidMountCallback: PropTypes.func.isRequired,
  152. componentWillUnmountCallback: PropTypes.func.isRequired,
  153. isSchematicType: PropTypes.func.isRequired,
  154. isSDKActive: PropTypes.func.isRequired
  155. }).isRequired,
  156. menuIcon: PropTypes.object
  157. };
  158. PreviewVisualItem.defaultProps = {
  159. menuIcon: Information_16
  160. };
  161. return PreviewVisualItem;
  162. });
  163. //# sourceMappingURL=PreviewVisualItem.js.map