@attivio/suit
Version:
Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.
81 lines (61 loc) • 3.1 kB
JavaScript
;
exports.__esModule = true;
exports.default = undefined;
var _class, _temp;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _Pager = require('./Pager');
var _Pager2 = _interopRequireDefault(_Pager);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
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; }
/**
* A Searcher-aware wrapper around the Pager component that triggers the Searcher to return the
* next/previous page of search results.
*/
var SearchResultsPager = (_temp = _class = function (_React$Component) {
_inherits(SearchResultsPager, _React$Component);
function SearchResultsPager(props) {
_classCallCheck(this, SearchResultsPager);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
_this.changePage = _this.changePage.bind(_this);
return _this;
}
SearchResultsPager.prototype.changePage = function changePage(newPage) {
var searcher = this.context.searcher;
if (searcher) {
searcher.changePage(newPage);
}
};
SearchResultsPager.prototype.render = function render() {
var searcher = this.context.searcher;
if (searcher) {
if (searcher.state.response) {
var pageSize = searcher.state.resultsPerPage;
if (pageSize > 0) {
var currentPage = Math.floor(searcher.state.resultsOffset / pageSize);
var totalHits = searcher.state.response.totalHits;
var numPages = Math.ceil(totalHits / pageSize);
return _react2.default.createElement(_Pager2.default, {
onPageChange: this.changePage,
currentPage: currentPage,
totalPages: numPages,
right: this.props.right
});
}
}
}
// No searcher or no results... return nothing;
return null;
};
return SearchResultsPager;
}(_react2.default.Component), _class.defaultProps = {
right: false
}, _class.contextTypes = {
searcher: _propTypes2.default.any
}, _class.displayName = 'SearchResultsPager', _temp);
exports.default = SearchResultsPager;
module.exports = exports['default'];