UNPKG

@attivio/suit

Version:

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

115 lines (92 loc) 5.06 kB
'use strict'; exports.__esModule = true; exports.default = undefined; var _class, _temp; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _SearchFacetBucket = require('../api/SearchFacetBucket'); var _SearchFacetBucket2 = _interopRequireDefault(_SearchFacetBucket); var _SentimentTagCloud = require('./SentimentTagCloud'); var _SentimentTagCloud2 = _interopRequireDefault(_SentimentTagCloud); 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; } /** 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 _SentimentTagCloud.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 _SentimentTagCloud.SentimentTagCloudValue(bucketLabel, record.count, 'negative')); } }); return _react2.default.createElement(_SentimentTagCloud2.default, { positiveTags: positiveTagCloudValues, negativeTags: negativeTagCloudValues, maxValues: this.props.maxBuckets, callback: this.tagCloudCallback }); }; return SentimentTagCloudFacetContents; }(_react2.default.Component), _class.displayName = 'SentimentTagCloudFacetContents', _temp); exports.default = SentimentTagCloudFacetContents; module.exports = exports['default'];