react-application-core
Version:
A react-based application core for the business applications.
219 lines • 9.22 kB
JavaScript
"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 (Object.prototype.hasOwnProperty.call(b, 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 });
exports.GridHeadColumn = void 0;
var React = require("react");
var definition_1 = require("../../../definition");
var util_1 = require("../../../util");
var base_column_1 = require("../base-column");
var GridHeadColumn = /** @class */ (function (_super) {
__extends(GridHeadColumn, _super);
/**
* @stable [09.12.2020]
* @param originalProps
*/
function GridHeadColumn(originalProps) {
var _this = _super.call(this, originalProps) || this;
_this.hintRef = React.createRef();
_this.onAscSortingActionClick = _this.onAscSortingActionClick.bind(_this);
_this.onCloseClick = _this.onCloseClick.bind(_this);
_this.onDescSortingActionClick = _this.onDescSortingActionClick.bind(_this);
return _this;
}
/**
* @stable [09.12.2020]
*/
GridHeadColumn.prototype.componentDidMount = function () {
this.doRefreshHint();
};
/**
* @stable [09.12.2020]
*/
GridHeadColumn.prototype.componentDidUpdate = function (prevProps) {
this.doRefreshHint(prevProps);
};
/**
* @stable [09.12.2020]
*/
GridHeadColumn.prototype.render = function () {
var _this = this;
var originalProps = this.originalProps;
var colSpan = originalProps.colSpan, headerClassName = originalProps.headerClassName, headerColSpan = originalProps.headerColSpan, headerRendered = originalProps.headerRendered;
return util_1.ConditionUtils.orNull(headerRendered, function () { return (React.createElement("th", { style: _this.styles, colSpan: util_1.NvlUtils.nvl(headerColSpan, colSpan), className: _this.getClassName(util_1.CalcUtils.calc(headerClassName, originalProps)) }, _this.columnContentElement)); });
};
/**
* @stable [28.07.2020]
* @param children
*/
GridHeadColumn.prototype.getColumnContentElement = function (children) {
var _a = this.originalProps, closed = _a.closed, sortable = _a.sortable;
var hasHint = this.hasHint;
var haveExtraActions = sortable || hasHint;
return (React.createElement(React.Fragment, null,
haveExtraActions && (React.createElement("div", { className: definition_1.GridClassesEnum.COLUMN_EXTRA_ACTIONS },
sortable && (React.createElement(React.Fragment, null,
this.uiFactory.makeIcon({
className: util_1.ClsUtils.joinClassName(definition_1.GridClassesEnum.EXTRA_ACTION, this.isDescSortingEnabled && definition_1.GridClassesEnum.ACTIVE_SORT_ACTION),
type: definition_1.IconsEnum.ARROW_DOWN,
onClick: this.onDescSortingActionClick,
}),
this.uiFactory.makeIcon({
className: util_1.ClsUtils.joinClassName(definition_1.GridClassesEnum.EXTRA_ACTION, this.isAscSortingEnabled && definition_1.GridClassesEnum.ACTIVE_SORT_ACTION),
type: definition_1.IconsEnum.ARROW_UP,
onClick: this.onAscSortingActionClick,
}))),
hasHint && React.cloneElement(this.uiFactory.makeIcon({
className: definition_1.GridClassesEnum.EXTRA_ACTION,
type: definition_1.IconsEnum.QUESTION,
}), { ref: this.hintRef }))),
this.hasCloseAction
? (React.createElement(React.Fragment, null,
children,
this.uiFactory.makeIcon({
type: closed ? definition_1.IconsEnum.CHEVRON_DOWN : definition_1.IconsEnum.CHEVRON_UP,
onClick: this.onCloseClick,
})))
: children));
};
/**
* @stable [28.07.2020]
*/
GridHeadColumn.prototype.onCloseClick = function () {
var _a = this.originalProps, closed = _a.closed, onClose = _a.onClose;
onClose(!closed);
};
/**
* @stable [28.07.2020]
*/
GridHeadColumn.prototype.onAscSortingActionClick = function () {
this.doSortingDirectionChange(util_1.ConditionUtils.orNull(!this.isAscSortingEnabled, definition_1.SortDirectionsEnum.ASC));
};
/**
* @stable [28.07.2020]
*/
GridHeadColumn.prototype.onDescSortingActionClick = function () {
this.doSortingDirectionChange(util_1.ConditionUtils.orNull(!this.isDescSortingEnabled, definition_1.SortDirectionsEnum.DESC));
};
/**
* @stable [19.07.2020]
* @param {SortDirectionsEnum} direction
*/
GridHeadColumn.prototype.doSortingDirectionChange = function (direction) {
var _a = this.originalProps, name = _a.name, onSortingDirectionChange = _a.onSortingDirectionChange;
if (util_1.TypeUtils.isFn(onSortingDirectionChange)) {
onSortingDirectionChange({ name: name, direction: direction });
}
};
/**
* @stable [08.12.2020]
* @private
*/
GridHeadColumn.prototype.doRefreshHint = function (prevProps) {
var hint = this.originalProps.hint;
if (util_1.ObjectUtils.isCurrentValueNotEqualPreviousValue(hint, prevProps === null || prevProps === void 0 ? void 0 : prevProps.hint)) {
util_1.TooltipUtils.init(this.hintElement, hint);
}
};
/**
* @stable [26.11.2020]
* @protected
*/
GridHeadColumn.prototype.isActionable = function () {
return _super.prototype.isActionable.call(this) || this.hasHint;
};
Object.defineProperty(GridHeadColumn.prototype, "isDescSortingEnabled", {
/**
* @stable [28.07.2020]
*/
get: function () {
return this.originalProps.direction === definition_1.SortDirectionsEnum.DESC;
},
enumerable: false,
configurable: true
});
Object.defineProperty(GridHeadColumn.prototype, "isAscSortingEnabled", {
/**
* @stable [28.07.2020]
*/
get: function () {
return this.originalProps.direction === definition_1.SortDirectionsEnum.ASC;
},
enumerable: false,
configurable: true
});
Object.defineProperty(GridHeadColumn.prototype, "styles", {
/**
* @stable [08.12.2020]
*/
get: function () {
var originalProps = this.originalProps;
var headerStyle = originalProps.headerStyle, headerWidth = originalProps.headerWidth;
return this.getStyle(__assign({ width: headerWidth }, util_1.CalcUtils.calc(headerStyle, originalProps)));
},
enumerable: false,
configurable: true
});
Object.defineProperty(GridHeadColumn.prototype, "hasHint", {
/**
* @stable [26.11.2020]
* @private
*/
get: function () {
return util_1.ObjectUtils.isObjectNotEmpty(this.originalProps.hint);
},
enumerable: false,
configurable: true
});
Object.defineProperty(GridHeadColumn.prototype, "hasCloseAction", {
/**
* @stable [08.12.2020]
* @private
*/
get: function () {
var _a = this.originalProps, closable = _a.closable, onClose = _a.onClose;
return closable && util_1.TypeUtils.isFn(onClose);
},
enumerable: false,
configurable: true
});
Object.defineProperty(GridHeadColumn.prototype, "hintElement", {
/**
* @stable [26.11.2020]
* @private
*/
get: function () {
return this.hintRef.current;
},
enumerable: false,
configurable: true
});
GridHeadColumn.defaultProps = util_1.PropsUtils.mergeWithParentDefaultProps({
headerRendered: true,
}, base_column_1.BaseGridColumn);
return GridHeadColumn;
}(base_column_1.BaseGridColumn));
exports.GridHeadColumn = GridHeadColumn;
//# sourceMappingURL=grid-head-column.component.js.map