solrkit
Version:
 
93 lines • 4.9 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var 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 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 });
var React = require("react");
var lodash_1 = require("lodash");
var semantic_ui_react_1 = require("semantic-ui-react");
var FacetTypes_1 = require("./FacetTypes");
var CheckFacet = (function (_super) {
__extends(CheckFacet, _super);
function CheckFacet() {
var _this = _super.call(this) || this;
_this.state = {
showMoreLink: true,
typeahead: ''
};
_this.onShowMore = _this.onShowMore.bind(_this);
_this.onChangeTypeahead = _this.onChangeTypeahead.bind(_this);
return _this;
}
CheckFacet.prototype.onClick = function (value) {
var _this = this;
return function () {
var selections = lodash_1.get(_this.context.searchState.facets, _this.props.facet, []);
if (lodash_1.includes(selections, value)) {
selections = selections.filter(function (f) { return f !== value; });
}
else {
selections.push(value);
}
var thisFacet = {};
thisFacet[_this.props.facet] = selections;
_this.context.transition({
start: 0,
facets: thisFacet
});
};
};
CheckFacet.prototype.onShowMore = function () {
this.setState({ showMoreLink: false });
};
CheckFacet.prototype.onChangeTypeahead = function (event) {
this.setState({ typeahead: event.currentTarget.value });
};
CheckFacet.prototype.render = function () {
var _this = this;
var title = this.props.title;
var help = this.props.help;
var renderValue = this.props.render || FacetTypes_1.defaultRenderer;
var valueList = (this.props.search && this.state.typeahead.length > 0 ? (lodash_1.filter(this.props.values, function (v) { return v[0].startsWith(_this.state.typeahead); })) : (this.props.values)).filter(!this.props.initialValues ? lodash_1.stubTrue : (function (row) {
return lodash_1.includes(_this.props.initialValues, row.value);
}));
if (valueList.length === 0) {
return null;
}
var minValues = this.props.minValues || 5;
var noMore = !this.state.showMoreLink || valueList.length < (minValues + 3);
var displayValues = (noMore) ? (valueList) : (lodash_1.take(valueList, minValues));
var moreLink = noMore ? (null) : (React.createElement("div", { style: { display: 'block', cursor: 'pointer' }, onClick: this.onShowMore }, "Show More"));
var searchBox = this.props.search && !noMore ? (React.createElement("form", { className: "ui mini form" },
React.createElement("div", { className: "field", style: { paddingBottom: '3px', width: '70%' } },
React.createElement("input", { type: "text", placeholder: "Filter", onChange: this.onChangeTypeahead })))) : null;
return (React.createElement("div", { className: "ui", style: { marginBottom: '1em' } },
title ? (help ? (React.createElement(semantic_ui_react_1.Popup, { trigger: React.createElement("h4", null, title), content: help })) :
React.createElement("h4", null, title))
: null,
searchBox,
lodash_1.orderBy(displayValues, ['checked', 'count'], ['desc', 'desc']).map(function (thisFacet, i) {
var value = thisFacet.value, count = thisFacet.count, checked = thisFacet.checked;
var onClick = _this.onClick(value);
return (React.createElement("div", { key: i, style: { display: 'block' } },
React.createElement("div", { key: "cb", className: "ui checkbox" },
React.createElement("input", { key: "input", onClick: onClick, checked: checked, type: "checkbox", name: i + '' }),
React.createElement("label", { key: "label", onClick: onClick, style: { cursor: 'pointer' } }, renderValue(value, count)))));
}),
moreLink));
};
CheckFacet.contextTypes = {
searchState: React.PropTypes.object,
transition: React.PropTypes.func
};
return CheckFacet;
}(React.Component));
exports.CheckFacet = CheckFacet;
//# sourceMappingURL=CheckFacet.js.map