UNPKG

@gooddata/react-components

Version:

GoodData.UI - A powerful JavaScript library for building analytical applications

135 lines • 7.68 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); // (C) 2007-2018 GoodData Corporation var React = require("react"); var noop = require("lodash/noop"); var difference = require("lodash/difference"); var uniq = require("lodash/uniq"); var get = require("lodash/get"); var IntlWrapper_1 = require("./base/IntlWrapper"); var TranslationsProvider_1 = require("./base/TranslationsProvider"); var fixEmptyHeaderItems_1 = require("./base/utils/fixEmptyHeaderItems"); var Table_1 = require("../../proptypes/Table"); var TotalsConverter_1 = require("../../helpers/TotalsConverter"); var VisualizationLoadingHOC_1 = require("./base/VisualizationLoadingHOC"); var BaseVisualization_1 = require("./base/BaseVisualization"); var Table_2 = require("../visualizations/table/Table"); var ResponsiveTable_1 = require("../visualizations/table/ResponsiveTable"); var TableTransformation_1 = require("../visualizations/table/TableTransformation"); var ROWS_PER_PAGE_IN_RESPONSIVE_TABLE = 9; var SimpleTable = /** @class */ (function (_super) { __extends(SimpleTable, _super); function SimpleTable(props) { var _this = _super.call(this, props) || this; _this.state = { page: 1, pageOffset: 0, lastAddedTotalType: null, }; _this.onSortChange = _this.onSortChange.bind(_this); _this.onMore = _this.onMore.bind(_this); _this.onLess = _this.onLess.bind(_this); _this.onTotalsEdit = _this.onTotalsEdit.bind(_this); _this.resetLastAddedTotalType = _this.resetLastAddedTotalType.bind(_this); return _this; } SimpleTable.prototype.componentWillReceiveProps = function (nextProps) { if (this.props.totals.length !== nextProps.totals.length) { var totalsTypes = uniq(this.props.totals.map(function (total) { return total.type; })); var nextTotalsTypes = uniq(nextProps.totals.map(function (total) { return total.type; })); this.setState({ lastAddedTotalType: difference(nextTotalsTypes, totalsTypes)[0] }); } }; SimpleTable.prototype.resetLastAddedTotalType = function () { this.setState({ lastAddedTotalType: null }); }; SimpleTable.prototype.onSortChange = function (sortItem) { this.props.pushData({ properties: { sortItems: [sortItem], }, }); }; SimpleTable.prototype.onTotalsEdit = function (indexedTotals) { var _a = this.props, dataSource = _a.dataSource, pushData = _a.pushData; var totals = TotalsConverter_1.convertToTotals(indexedTotals, dataSource.getAfm()); pushData({ properties: { totals: totals, }, }); }; SimpleTable.prototype.onMore = function (_a) { var page = _a.page, pageOffset = _a.pageOffset; this.setState({ page: page, pageOffset: pageOffset, }); }; SimpleTable.prototype.onLess = function () { this.setState({ page: 1, pageOffset: 0, }); }; SimpleTable.prototype.renderVisualization = function () { var tableRenderer = this.getTableRenderer(); return this.renderTable(tableRenderer); }; SimpleTable.prototype.getTableRenderer = function () { var _this = this; var _a = this.props, environment = _a.environment, maxHeight = _a.maxHeight; var _b = this.state, page = _b.page, pageOffset = _b.pageOffset; if (environment === "dashboards") { return function (props) { return (React.createElement(ResponsiveTable_1.ResponsiveTable, __assign({}, props, { rows: props.rows || [], rowsPerPage: ROWS_PER_PAGE_IN_RESPONSIVE_TABLE, page: page, pageOffset: pageOffset, onMore: _this.onMore, onLess: _this.onLess, onSortChange: _this.onSortChange, executionRequest: _this.getExecutionRequest() }))); }; } return function (props) { return (React.createElement(Table_2.Table, __assign({}, props, { containerMaxHeight: maxHeight, onSortChange: _this.onSortChange, executionRequest: _this.getExecutionRequest() }))); }; }; SimpleTable.prototype.getExecutionRequest = function () { return { execution: { afm: this.props.dataSource.getAfm(), resultSpec: this.props.resultSpec, }, }; }; SimpleTable.prototype.renderTable = function (tableRenderer) { var _this = this; var _a = this.props, afterRender = _a.afterRender, dataSource = _a.dataSource, drillableItems = _a.drillableItems, height = _a.height, maxHeight = _a.maxHeight, locale = _a.locale, stickyHeaderOffset = _a.stickyHeaderOffset, environment = _a.environment, resultSpec = _a.resultSpec, onFiredDrillEvent = _a.onFiredDrillEvent, totals = _a.totals, totalsEditAllowed = _a.totalsEditAllowed, execution = _a.execution; var separators = get(this.props, "config.separators", undefined); var onDataTooLarge = environment === "dashboards" ? this.props.onDataTooLarge : noop; // Short term solution (See BB-641) var indexedTotals = TotalsConverter_1.convertToIndexedTotals(totals, dataSource.getAfm(), resultSpec); return (React.createElement(IntlWrapper_1.IntlWrapper, { locale: locale }, React.createElement(TranslationsProvider_1.IntlTranslationsProvider, null, function (props) { return (React.createElement(TableTransformation_1.TableTransformation, { executionRequest: _this.getExecutionRequest(), executionResponse: execution.executionResponse, executionResult: fixEmptyHeaderItems_1.fixEmptyHeaderItems(execution.executionResult, props.emptyHeaderString), afterRender: afterRender, config: { stickyHeaderOffset: stickyHeaderOffset, separators: separators }, drillableItems: drillableItems, height: height, maxHeight: maxHeight, onDataTooLarge: onDataTooLarge, tableRenderer: tableRenderer, onFiredDrillEvent: onFiredDrillEvent, totals: indexedTotals, totalsEditAllowed: totalsEditAllowed, onTotalsEdit: _this.onTotalsEdit, lastAddedTotalType: _this.state.lastAddedTotalType, onLastAddedTotalRowHighlightPeriodEnd: _this.resetLastAddedTotalType })); }))); }; SimpleTable.defaultProps = __assign({}, VisualizationLoadingHOC_1.commonDefaultProps, { stickyHeaderOffset: 0, height: null, maxHeight: null, environment: "none", totals: [], totalsEditAllowed: false, onTotalsEdit: noop, onDataTooLarge: noop }); SimpleTable.propTypes = Table_1.TablePropTypes; return SimpleTable; }(BaseVisualization_1.BaseVisualization)); exports.PureTable = VisualizationLoadingHOC_1.visualizationLoadingHOC(SimpleTable); //# sourceMappingURL=PureTable.js.map