DataBehindTheVisView.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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: Dashboard
  8. * (C) Copyright IBM Corp. 2017, 2020
  9. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define(['react', 'react-dom', 'ca-ui-toolkit', 'underscore', '../../../datatray/ExtensionBaseView', '../../../lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/illustrations-js/no-data_200', '../../../dataSources/nls/StringResources'], function (React, ReactDOM, toolkit, _, BaseView, noData200, StringResources) {
  12. var ContextualGrid = function (_BaseView) {
  13. _inherits(ContextualGrid, _BaseView);
  14. function ContextualGrid(options) {
  15. _classCallCheck(this, ContextualGrid);
  16. var _this = _possibleConstructorReturn(this, _BaseView.call(this, options));
  17. _this.dashboard = options.dashboard;
  18. _this.logger = _this.dashboard.getGlassCoreSvc('.Logger');
  19. return _this;
  20. }
  21. ContextualGrid.prototype.render = function render(content, container) {
  22. var _this2 = this;
  23. if (this.content !== content || this.containerNode !== container) {
  24. this.setViewContext(content, container);
  25. }
  26. BaseView.clearContainer(this.containerNode);
  27. // class name is needed for using style from ba-ui-toolkit
  28. this.containerNode.classList.add('ba-theme-waca');
  29. // get the view option from vis grid model in widget model
  30. var doAggregate = content.getPropertyValue('datagrid.viewOption') === 'projectedAggregated';
  31. this._setLoading();
  32. return this.content.getFeature('DataBehindTheVis').getData(doAggregate).then(function (results) {
  33. _this2._removeLoading();
  34. if (_this2._isResultValid(results)) {
  35. _this2._renderReactGrid(results);
  36. } else {
  37. _this2._noData();
  38. }
  39. }).catch(function (error) {
  40. var knownErrors = ['dwErrorStaleRequest'];
  41. var errorMessage = error && (error.message || error.msg) || 'dwErrorRenderingContextualGrid';
  42. if (knownErrors.indexOf(errorMessage) === -1) {
  43. //TODO: we could introduce a bad state view here
  44. _this2._removeLoading();
  45. _this2.logger.error(error);
  46. } else {
  47. _this2.logger.warn(error);
  48. }
  49. });
  50. };
  51. ContextualGrid.prototype.setViewContext = function setViewContext(content, container) {
  52. this._deregisterEvents();
  53. this.content = content;
  54. this.containerNode = container;
  55. this._registerEvents();
  56. };
  57. ContextualGrid.prototype._noData = function _noData() {
  58. var svg = React.createElement('svg', { viewBox: noData200.default.viewBox, focusable: 'false', className: 'noDataSvg' }, React.createElement('use', { class: 'ba-graphics-themable', xlinkHref: '#' + noData200.default.id, fill: '#00baa1' }));
  59. var text = React.createElement('p', {}, StringResources.get('DATA_TRAY_no_data_text'));
  60. var content = React.createElement('div', { className: 'noDataContent' }, svg, text);
  61. ReactDOM.render(content, this.containerNode);
  62. };
  63. ContextualGrid.prototype.remove = function remove() {
  64. ContextualGrid.inherited('remove', this, arguments);
  65. this._deregisterEvents();
  66. this._unmountReactComponents();
  67. };
  68. ContextualGrid.prototype._unmountReactComponents = function _unmountReactComponents() {
  69. if (this.containerNode) {
  70. ReactDOM.unmountComponentAtNode(this.containerNode);
  71. }
  72. };
  73. ContextualGrid.prototype._registerEvents = function _registerEvents() {
  74. if (this.content) {
  75. this._renderHandler = this.render.bind(this, this.content, this.containerNode);
  76. this.content.on('change:property:datagrid.viewOption', this._renderHandler, this);
  77. }
  78. };
  79. ContextualGrid.prototype._deregisterEvents = function _deregisterEvents() {
  80. if (this.content) {
  81. this.content.off('change:property:datagrid.viewOption', this._renderHandler, this);
  82. }
  83. };
  84. ContextualGrid.prototype._renderReactGrid = function _renderReactGrid(results) {
  85. var _this3 = this;
  86. var props = {
  87. numColumns: results.headers.length,
  88. numRows: results.cells.length,
  89. fixedRows: 1,
  90. useRowOptionsColumn: true,
  91. rowOptionsColumnText: StringResources.get('contextualGridMenuLabel'),
  92. dataCellRenderer: this._cellRenderer.bind(this, results),
  93. fixedRowCellRenderer: function fixedRowCellRenderer(_, colIndex, gridCellProps) {
  94. var headerData = results.headers[colIndex];
  95. var reactEle = React.createElement(toolkit.GridHeaderCell, gridCellProps, React.createElement('div', {
  96. style: BaseView.CELL.style.left
  97. }, headerData));
  98. reactEle.displayName = 'RowCell';
  99. return reactEle;
  100. },
  101. onFixedCornerCellMenu: function onFixedCornerCellMenu(clientX, clientY) {
  102. _this3.dashboard.showContextMenu({
  103. position: {
  104. pageX: clientX,
  105. pageY: clientY
  106. },
  107. menuId: 'com.ibm.bi.dashboard.contextualGridMenu',
  108. activeObject: {
  109. content: _this3.content,
  110. export: _this3._export.bind(_this3, results)
  111. }
  112. });
  113. }
  114. };
  115. var contextualGrid = React.createElement(toolkit.Grid, props);
  116. ReactDOM.render(contextualGrid, this.containerNode);
  117. };
  118. ContextualGrid.prototype._export = function _export(results) {
  119. this.dashboard.getFeature('CsvExport').export(results.title, [results.headers], results.cells);
  120. };
  121. ContextualGrid.prototype._cellRenderer = function _cellRenderer(results, rowIndex, colIndex, gridCellProps) {
  122. var dataCellObj = results.cells[rowIndex][colIndex];
  123. var style = BaseView.CELL.style.left;
  124. if (this._isCellValueMeasure(dataCellObj)) {
  125. style = BaseView.CELL.style.right;
  126. }
  127. return this._getCellComponent(dataCellObj, gridCellProps, style);
  128. };
  129. ContextualGrid.prototype._isCellValueMeasure = function _isCellValueMeasure(dataCell) {
  130. return dataCell && _.isUndefined(dataCell.label);
  131. };
  132. ContextualGrid.prototype._getCellComponent = function _getCellComponent(dataCell, gridCellProps, style) {
  133. if (style) {
  134. style['white-space'] = 'nowrap'; /*Deal with very long column value*/
  135. }
  136. var dataCellValue = dataCell.toString();
  137. var reactEle = React.createElement(toolkit.GridCell, gridCellProps, React.createElement('div', {
  138. style: style,
  139. title: dataCellValue
  140. }, dataCellValue));
  141. reactEle.displayName = 'Cell';
  142. return reactEle;
  143. };
  144. ContextualGrid.prototype._isResultValid = function _isResultValid(result) {
  145. return result.cells.length && result.headers.length;
  146. };
  147. return ContextualGrid;
  148. }(BaseView);
  149. return ContextualGrid;
  150. });
  151. //# sourceMappingURL=DataBehindTheVisView.js.map