client/entity-editor/annotation-section/annotation-section.js

"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 _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,
    isUnifiedForm = _ref.isUnifiedForm;
  var annotation = (0, _utils.convertMapToObject)(immutableAnnotation);
  var annotationLabel = /*#__PURE__*/_react.default.createElement("span", null, "Annotation", /*#__PURE__*/_react.default.createElement("span", {
    className: "text-muted"
  }, " (optional)"));
  var tooltip = /*#__PURE__*/_react.default.createElement(_reactBootstrap.Tooltip, null, "Additional freeform data that does not fit in the above form");
  var lgCol = {
    offset: 3,
    span: 6
  };
  if (isUnifiedForm) {
    lgCol.offset = 0;
  }
  var heading = /*#__PURE__*/_react.default.createElement("h2", null, " 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"
  }, "Last modified: ", (0, _utils.formatDate)(new Date(annotation.lastRevision.createdAt))), /*#__PURE__*/_react.default.createElement("p", {
    className: "text-muted"
  }, "Annotations allow you to enter freeform data that does not otherwise fit in the above form.", /*#__PURE__*/_react.default.createElement("b", null, " Do not submit any copyrighted text here."), " The contents will be made available to the public under ", /*#__PURE__*/_react.default.createElement("a", {
    href: "https://musicbrainz.org/doc/About/Data_License"
  }, "open licenses"), "."))));
}
AnnotationSection.displayName = 'AnnotationSection';
AnnotationSection.propTypes = {
  annotation: _propTypes.default.object.isRequired,
  isUnifiedForm: _propTypes.default.bool,
  onAnnotationChange: _propTypes.default.func.isRequired
};
AnnotationSection.defaultProps = {
  isUnifiedForm: false
};
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 = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(AnnotationSection);
exports.default = _default;
//# sourceMappingURL=annotation-section.js.map