UNPKG

@gooddata/react-components

Version:

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

84 lines 4.28 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 __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); // (C) 2007-2020 GoodData Corporation var React = require("react"); var PropTypes = require("prop-types"); var agGridUtils_1 = require("./agGridUtils"); var HeaderCell_1 = require("./HeaderCell"); var agGridConst_1 = require("./agGridConst"); exports.ASC = "asc"; exports.DESC = "desc"; var ColumnHeader = /** @class */ (function (_super) { __extends(ColumnHeader, _super); function ColumnHeader() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = { sorting: null, }; _this.getCurrentSortDirection = function () { var currentSort = _this.props.column.getSort(); _this.setState({ sorting: currentSort, }); }; _this.onSortRequested = function (sortDir) { var multiSort = false; // Enable support for multisort with CMD key with 'event.shiftKey'; _this.props.setSort(sortDir, multiSort); }; return _this; } ColumnHeader.prototype.componentWillMount = function () { this.props.column.addEventListener("sortChanged", this.getCurrentSortDirection); this.setState({ sorting: this.props.column.getSort(), }); }; ColumnHeader.prototype.componentWillUnmount = function () { this.props.column.removeEventListener("sortChanged", this.getCurrentSortDirection); }; ColumnHeader.prototype.getDefaultSortDirection = function () { return this.getFieldType() === agGridConst_1.FIELD_TYPE_ATTRIBUTE ? exports.ASC : exports.DESC; }; ColumnHeader.prototype.render = function () { var _a = this.props, displayName = _a.displayName, enableSorting = _a.enableSorting, menu = _a.menu, column = _a.column, getAfmFilters = _a.getAfmFilters, onMenuAggregationClick = _a.onMenuAggregationClick, getColumnTotals = _a.getColumnTotals, getExecutionResponse = _a.getExecutionResponse, intl = _a.intl; var sorting = this.state.sorting; var textAlign = this.getFieldType() === agGridConst_1.FIELD_TYPE_ATTRIBUTE ? HeaderCell_1.ALIGN_LEFT : HeaderCell_1.ALIGN_RIGHT; var isColumnAttribute = column.getColDef().type === agGridConst_1.COLUMN_ATTRIBUTE_COLUMN; return (React.createElement(HeaderCell_1.default, { className: "s-pivot-table-column-header", textAlign: textAlign, displayText: displayName, enableSorting: !isColumnAttribute && enableSorting, sortDirection: sorting, defaultSortDirection: this.getDefaultSortDirection(), onSortClick: this.onSortRequested, onMenuAggregationClick: onMenuAggregationClick, menu: menu, colId: column.getColDef().field, getColumnTotals: getColumnTotals, getExecutionResponse: getExecutionResponse, intl: intl, getAfmFilters: getAfmFilters })); }; ColumnHeader.prototype.getFieldType = function () { var colId = this.props.column.getColDef().field; var fields = agGridUtils_1.getParsedFields(colId); var lastFieldType = fields[fields.length - 1][0]; return lastFieldType; }; ColumnHeader.propTypes = { menu: PropTypes.object, getColumnTotals: PropTypes.func, getExecutionResponse: PropTypes.func, onMenuAggregationClick: PropTypes.func, intl: PropTypes.object, enableSorting: PropTypes.bool, displayName: PropTypes.string, column: PropTypes.any, reactContainer: PropTypes.any, showColumnMenu: PropTypes.func, setSort: PropTypes.func, }; return ColumnHeader; }(React.Component)); exports.default = ColumnHeader; //# sourceMappingURL=ColumnHeader.js.map