UNPKG

react-application-core

Version:

A react-based application core for the business applications.

216 lines 8.42 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 (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 __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseList = void 0; var React = require("react"); var R = require("ramda"); var util_1 = require("../../util"); var universal_component_1 = require("../base/universal.component"); var info_component_1 = require("../info/info.component"); var page_toolbar_component_1 = require("../toolbar/page/page-toolbar.component"); var definition_1 = require("../../definition"); var BaseList = /** @class */ (function (_super) { __extends(BaseList, _super); /** * @stable [16.07.2020] * @param {TProps} props */ function BaseList(props) { var _this = _super.call(this, props) || this; _this.fireRefreshEvent = _this.fireRefreshEvent.bind(_this); _this.onLocalPagingFirst = _this.onLocalPagingFirst.bind(_this); _this.onLocalPagingNext = _this.onLocalPagingNext.bind(_this); _this.onLocalPagingPrevious = _this.onLocalPagingPrevious.bind(_this); return _this; } /** * @stable [21.06.2018] * @returns {JSX.Element} */ BaseList.prototype.render = function () { var props = this.props; if (this.originalDataSourceDoesNotExist || this.areDataMissing || props.progress || props.error) { return this.getMessage(); } return this.getView(); }; /** * @stable [16.07.2020] * @param {IListRowsConfigEntity} cfg * @returns {JSX.Element} */ BaseList.prototype.getPageToolbarElement = function (cfg) { var _this = this; var _a = this.originalProps, localPagination = _a.localPagination, pageSize = _a.pageSize; if (!localPagination) { return null; } var page = this.state.page; return (React.createElement(page_toolbar_component_1.PageToolbar, { page: page, pageSize: pageSize, totalCount: cfg.totalCount, onFirst: this.onLocalPagingFirst, onLast: function () { return _this.setState({ page: cfg.pagesCount }, _this.fireRefreshEvent); }, onNext: this.onLocalPagingNext, onPrevious: this.onLocalPagingPrevious })); }; BaseList.prototype.getMessage = function () { var _a = this.props, emptyDataMessage = _a.emptyDataMessage, emptyMessage = _a.emptyMessage, error = _a.error, progress = _a.progress; var areDataMissing = this.areDataMissing; return (React.createElement(info_component_1.Info, { error: error, message: emptyMessage, progress: progress, emptyData: areDataMissing ? util_1.NvlUtils.nvl(emptyDataMessage, areDataMissing) : areDataMissing })); }; /** * @stable [10.06.2020] * @param {IEntity} entity * @returns {boolean} */ BaseList.prototype.isEntitySelected = function (entity) { return util_1.FilterUtils.SAME_ENTITY_PREDICATE(this.originalProps.selected, entity); }; /** * @stable [04.05.2020] * @param {IEntity} entity * @returns {string} */ BaseList.prototype.toRowKey = function (entity) { return "data-row-" + (R.isNil(entity.id) ? util_1.uuid() : entity.id); }; Object.defineProperty(BaseList.prototype, "originalDataSource", { /** * @stable [04.05.2020] * @returns {IEntity[]} */ get: function () { return this.props.data; }, enumerable: false, configurable: true }); Object.defineProperty(BaseList.prototype, "dataSource", { /** * @stable [17.06.2018] * @returns {IEntity[]} */ get: function () { var filteredAndSortedEntities = util_1.filterAndSortEntities(this.filterAndSortOriginalDataSourceUsingLocalFiltersAndSorters(), // @ts-ignore TODO this.props); var toNumber = this.toNumber; var pagedData; return R.isNil(toNumber) // Remote and local pagination are supported simultaneously. // The length result is equal to zero in a remote pagination case || (pagedData = filteredAndSortedEntities.slice(this.fromNumber, toNumber)).length === 0 ? filteredAndSortedEntities : pagedData; }, enumerable: false, configurable: true }); /** * @stable [06.06.2018] * @returns {IEntity[]} */ BaseList.prototype.filterAndSortOriginalDataSourceUsingLocalFiltersAndSorters = function () { return this.originalDataSource; }; /** * @stable [16.07.2020] */ BaseList.prototype.onLocalPagingNext = function () { this.setState(function (previousState) { return ({ page: previousState.page + 1 }); }, this.fireRefreshEvent); }; /** * @stable [16.07.2020] */ BaseList.prototype.onLocalPagingPrevious = function () { this.setState(function (previousState) { return ({ page: previousState.page - 1 }); }, this.fireRefreshEvent); }; /** * @stable [16.07.2020] */ BaseList.prototype.onLocalPagingFirst = function () { this.setState(function (previousState) { return ({ page: definition_1.DefaultEntities.FIRST_PAGE }); }, this.fireRefreshEvent); }; /** * @stable [16.07.2020] */ BaseList.prototype.fireRefreshEvent = function () { this.eventEmitter.emit(definition_1.SyntheticEmitterEventsEnum.REFRESH); // To update synthetic scrollbar }; Object.defineProperty(BaseList.prototype, "isRemoteMode", { /** * @stable [18.10.2018] * @returns {boolean} */ get: function () { return !this.props.localFiltration; }, enumerable: false, configurable: true }); Object.defineProperty(BaseList.prototype, "areDataMissing", { /** * @stable [17.06.2018] * @returns {boolean} */ get: function () { if (this.originalDataSourceDoesNotExist) { return false; // It's important to show the difference between the conditions: length === 0 and data === null! } var dataSource = this.isRemoteMode ? this.dataSource : this.originalDataSource; // In the case of a local filtering we need to get a false result return Array.isArray(dataSource) && dataSource.length === 0; }, enumerable: false, configurable: true }); Object.defineProperty(BaseList.prototype, "originalDataSourceDoesNotExist", { /** * @stable [17.06.2018] * @returns {boolean} */ get: function () { return R.isNil(this.originalDataSource); }, enumerable: false, configurable: true }); Object.defineProperty(BaseList.prototype, "fromNumber", { /** * @stable [10.06.2020] * @returns {number} */ get: function () { return util_1.PageUtils.pageCursorFrom(this.originalProps) - 1; }, enumerable: false, configurable: true }); Object.defineProperty(BaseList.prototype, "toNumber", { /** * @stable [10.06.2020] * @returns {number} */ get: function () { return util_1.PageUtils.pageCursorTo(this.originalProps); }, enumerable: false, configurable: true }); return BaseList; }(universal_component_1.UniversalComponent)); exports.BaseList = BaseList; //# sourceMappingURL=base-list.component.js.map