@attivio/suit
Version:
Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.
124 lines (101 loc) • 4.71 kB
JavaScript
'use strict';
exports.__esModule = true;
exports.default = undefined;
var _class, _temp2;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _Card = require('./Card');
var _Card2 = _interopRequireDefault(_Card);
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; }
/**
* The display card for a Placement query result.
*/
var PlacementResult = (_temp2 = _class = function (_React$Component) {
_inherits(PlacementResult, _React$Component);
function PlacementResult() {
var _temp, _this, _ret;
_classCallCheck(this, PlacementResult);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.onPromotionClick = function () {
var _this$props = _this.props,
linkUrl = _this$props.linkUrl,
linkText = _this$props.linkText,
imageUrl = _this$props.imageUrl;
var searcher = _this.context.searcher;
if (!searcher) {
return;
}
// The docId for the signal is of the format:
// '{Display Text} - {Destination Link}' -- if the promotion is Link
// '{Image URL} - {Destination Link}' -- if the promotion is Image
// The docOrdinal for link promotion is 1 and image promotion is 2
var signalDocId = imageUrl ? imageUrl + ' - ' + (linkUrl || '') : (linkText || '') + ' - ' + (linkUrl || '');
var signalDocOrdinal = imageUrl ? 2 : 1;
searcher.addPromotionSignal(signalDocId, signalDocOrdinal);
}, _temp), _possibleConstructorReturn(_this, _ret);
}
PlacementResult.prototype.renderMarkupIframe = function renderMarkupIframe() {
var getBlobURL = function getBlobURL(code) {
var blob = new Blob([code], { type: 'text/html' });
return URL.createObjectURL(blob);
};
var source = '\n <html>\n <body>\n ' + (this.props.markup || '') + '\n </body>\n </html>\n ';
var iframeSource = getBlobURL(source);
return _react2.default.createElement('iframe', {
title: 'Promotions frame',
style: { margin: '0px', border: '0px', width: '100%', height: '100%', frameBorder: '0', overflow: 'hidden' },
src: iframeSource
});
};
PlacementResult.prototype.render = function render() {
if (this.props.markup) {
return _react2.default.createElement(
_Card2.default,
{ style: { marginBottom: '10px', border: '0px', padding: '0px' } },
this.renderMarkupIframe()
);
}
var rawText = this.props.linkText || '';
var text = _react2.default.createElement(
'h4',
null,
rawText
);
var contents = this.props.imageUrl ? _react2.default.createElement(
'div',
null,
_react2.default.createElement('img', {
src: this.props.imageUrl,
title: rawText,
alt: rawText
}),
text
) : text;
return _react2.default.createElement(
_Card2.default,
{ style: { marginBottom: '10px' } },
this.props.linkUrl ? _react2.default.createElement(
'a',
{ href: this.props.linkUrl, onClick: this.onPromotionClick },
contents
) : contents
);
};
return PlacementResult;
}(_react2.default.Component), _class.defaultProps = {
linkUrl: null,
linkText: null,
imageUrl: null,
markup: null
}, _class.displayName = 'PlacementResult', _class.contextTypes = {
searcher: _propTypes2.default.any
}, _temp2);
exports.default = PlacementResult;
module.exports = exports['default'];