"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _reactBootstrap = require("react-bootstrap");
var _reactI18next = require("react-i18next");
var _utils = require("../../helpers/utils");
var _reactFontawesome = require("@fortawesome/react-fontawesome");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _reactRedux = require("react-redux");
var _actions = require("./actions");
var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
/*
* Copyright (C) 2020 Nicolas Pelletier
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* Container component. The AnnotationSection component contains a
* field for entering or modifying annotations for this entity.
*
* @param {Object} props - The properties passed to the component.
* @param {Object} props.annotation - The annotation object containing
* its content and lastRevision info
* @param {Function} props.onAnnotationChange - A function to be called when the
* annotation is changed.
* @returns {ReactElement} React element containing the rendered
* AnnotationSection.
*/
function AnnotationSection(_ref) {
var immutableAnnotation = _ref.annotation,
onAnnotationChange = _ref.onAnnotationChange,
_ref$isUnifiedForm = _ref.isUnifiedForm,
isUnifiedForm = _ref$isUnifiedForm === void 0 ? false : _ref$isUnifiedForm;
var _useTranslation = (0, _reactI18next.useTranslation)(),
translate = _useTranslation.t;
var annotation = (0, _utils.convertMapToObject)(immutableAnnotation);
var annotationLabel = /*#__PURE__*/_react.default.createElement("span", null, translate('common.annotation'), /*#__PURE__*/_react.default.createElement("span", {
className: "text-muted"
}, " ", translate('entityEditor.shared.optionalLabel')));
var tooltip = /*#__PURE__*/_react.default.createElement(_reactBootstrap.Tooltip, null, translate('entityEditor.annotationSection.tooltip'));
var lgCol = {
offset: 3,
span: 6
};
if (isUnifiedForm) {
lgCol.offset = 0;
}
var heading = /*#__PURE__*/_react.default.createElement("h2", null, " ", translate('common.annotation'));
return /*#__PURE__*/_react.default.createElement("div", null, !isUnifiedForm && heading, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Row, null, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Col, {
lg: lgCol
}, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Form.Group, null, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Form.Label, null, annotationLabel, /*#__PURE__*/_react.default.createElement(_reactBootstrap.OverlayTrigger, {
delay: 50,
overlay: tooltip
}, /*#__PURE__*/_react.default.createElement(_reactFontawesome.FontAwesomeIcon, {
className: "margin-left-0-5",
icon: _freeSolidSvgIcons.faQuestionCircle
}))), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Form.Control, {
as: "textarea",
defaultValue: annotation.content,
rows: "4",
onChange: onAnnotationChange
})), annotation && annotation.lastRevision && /*#__PURE__*/_react.default.createElement("p", {
className: "small text-muted"
}, translate('entityEditor.annotationSection.lastModified', {
date: (0, _utils.formatDate)(new Date(annotation.lastRevision.createdAt))
})), /*#__PURE__*/_react.default.createElement("p", {
className: "text-muted"
}, translate('entityEditor.annotationSection.helpText'), /*#__PURE__*/_react.default.createElement("b", null, " ", translate('entityEditor.annotationSection.copyrightWarning')), ' ', /*#__PURE__*/_react.default.createElement(_reactI18next.Trans, {
components: {
licenseLink: /*#__PURE__*/_react.default.createElement("a", {
href: "https://musicbrainz.org/doc/About/Data_License"
})
},
i18nKey: "entityEditor.annotationSection.openLicenseNotice"
})))));
}
AnnotationSection.displayName = 'AnnotationSection';
AnnotationSection.propTypes = {
annotation: _propTypes.default.object.isRequired,
isUnifiedForm: _propTypes.default.bool,
onAnnotationChange: _propTypes.default.func.isRequired
};
function mapStateToProps(rootState) {
return {
annotation: rootState.get('annotationSection')
};
}
function mapDispatchToProps(dispatch) {
return {
onAnnotationChange: function onAnnotationChange(event) {
return dispatch((0, _actions.debounceUpdateAnnotation)(event.target.value));
}
};
}
var _default = exports.default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(AnnotationSection);
//# sourceMappingURL=annotation-section.js.map