@attivio/suit
Version:
Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.
78 lines (60 loc) • 3.28 kB
JavaScript
var _class, _temp;
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; }
import React from 'react';
import PropTypes from 'prop-types';
import SearchFacetBucket from '../api/SearchFacetBucket';
import FacetFilter from '../api/FacetFilter';
import TagCloud, { TagCloudValue } from './TagCloud';
/** Display a facet's bucket values in a list with TagClouds. */
var TagCloudFacetContents = (_temp = _class = function (_React$Component) {
_inherits(TagCloudFacetContents, _React$Component);
function TagCloudFacetContents(props) {
_classCallCheck(this, TagCloudFacetContents);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
_this.tagCloudCallback = _this.tagCloudCallback.bind(_this);
return _this;
} // eslint-disable-line max-len
TagCloudFacetContents.prototype.tagCloudCallback = function tagCloudCallback(tcv) {
var selectedBucket = this.props.buckets.find(function (bucket) {
var bucketLabel = bucket.displayLabel();
return bucketLabel === tcv.label;
});
if (selectedBucket) {
this.props.addFacetFilter(selectedBucket);
}
};
/**
* Check if the search filter already has this bucket filter applied.
* The tag should be noLink or non-clickable if the respective tag is applied to the filter.
*/
TagCloudFacetContents.prototype.isTagNoLink = function isTagNoLink(bucket) {
var searcher = this.context.searcher;
var facetFilters = searcher ? searcher.state.facetFilters : [];
var isBucketFilterApplied = facetFilters.some(function (facetFilter) {
return facetFilter.filter === bucket.filter;
});
return isBucketFilterApplied;
};
TagCloudFacetContents.prototype.render = function render() {
var _this2 = this;
var tagCloudValues = this.props.buckets.map(function (bucket) {
var bucketLabel = bucket.displayLabel();
var noLink = _this2.isTagNoLink(bucket);
return new TagCloudValue(bucketLabel, bucket.count, noLink);
});
return React.createElement(TagCloud, {
tags: tagCloudValues,
maxValues: this.props.maxBuckets,
noLink: this.props.noLink,
callback: this.tagCloudCallback
});
};
return TagCloudFacetContents;
}(React.Component), _class.displayName = 'TagCloudFacetContents', _class.defaultProps = {
noLink: false
}, _class.contextTypes = {
searcher: PropTypes.any
}, _temp);
export { TagCloudFacetContents as default };