UNPKG

@attivio/suit

Version:

Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.

100 lines (84 loc) 4.61 kB
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 SearchFacetBucket from '../api/SearchFacetBucket'; import SentimentTagCloud, { SentimentTagCloudValue } from './SentimentTagCloud'; /** Display the values for positive and negative keyphrases in a list with TagClouds. */ var SentimentTagCloudFacetContents = (_temp = _class = function (_React$Component) { _inherits(SentimentTagCloudFacetContents, _React$Component); // Check if keyphrase bucket is a part of keyphrase bucketList // and if the count for bucket is greater than it's match in the bucketList, // if so, return bucket with count updated as the difference in values of count of matching buckets; // otherwise return null SentimentTagCloudFacetContents.handleDuplicateBucketInBucketList = function handleDuplicateBucketInBucketList(bucket, bucketList) { var i = void 0; var currentBucket = bucket; for (i = 0; i < bucketList.length; i += 1) { if (bucketList[i].value === currentBucket.value) { if (bucketList[i].count < currentBucket.count) { currentBucket.count -= bucketList[i].count; return currentBucket; } else if (bucketList[i].count > currentBucket.count) { return null; } else if (bucketList[i].count === currentBucket.count) { return currentBucket; } } } return currentBucket; }; function SentimentTagCloudFacetContents(props) { _classCallCheck(this, SentimentTagCloudFacetContents); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.tagCloudCallback = _this.tagCloudCallback.bind(_this); return _this; } SentimentTagCloudFacetContents.prototype.tagCloudCallback = function tagCloudCallback(tcv) { var selectedBucket = {}; if (tcv.sentiment === 'positive') { selectedBucket.value = this.props.positiveBuckets.find(function (bucket) { var bucketLabel = bucket.displayLabel(); return bucketLabel === tcv.label; }); selectedBucket.sentiment = 'positive'; } else if (tcv.sentiment === 'negative') { selectedBucket.value = this.props.negativeBuckets.find(function (bucket) { var bucketLabel = bucket.displayLabel(); return bucketLabel === tcv.label; }); selectedBucket.sentiment = 'negative'; } if (selectedBucket) { this.props.addFacetFilter(selectedBucket); } }; SentimentTagCloudFacetContents.prototype.render = function render() { var _this2 = this; var positiveTagCloudValues = []; this.props.positiveBuckets.forEach(function (bucket) { var record = _this2.constructor.handleDuplicateBucketInBucketList(bucket, _this2.props.negativeBuckets); if (record) { var bucketLabel = record.displayLabel(); positiveTagCloudValues.push(new SentimentTagCloudValue(bucketLabel, record.count, 'positive')); } }); var negativeTagCloudValues = []; this.props.negativeBuckets.forEach(function (bucket) { var record = _this2.constructor.handleDuplicateBucketInBucketList(bucket, _this2.props.positiveBuckets); if (record) { var bucketLabel = record.displayLabel(); negativeTagCloudValues.push(new SentimentTagCloudValue(bucketLabel, record.count, 'negative')); } }); return React.createElement(SentimentTagCloud, { positiveTags: positiveTagCloudValues, negativeTags: negativeTagCloudValues, maxValues: this.props.maxBuckets, callback: this.tagCloudCallback }); }; return SentimentTagCloudFacetContents; }(React.Component), _class.displayName = 'SentimentTagCloudFacetContents', _temp); export { SentimentTagCloudFacetContents as default };