client/entity-editor/edition-group-section/edition-group-section.js

"use strict";

require("core-js/modules/es.array.iterator.js");
require("core-js/modules/es.string.iterator.js");
require("core-js/modules/es.weak-map.js");
require("core-js/modules/web.dom-collections.iterator.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("core-js/modules/es.array.map.js");
require("core-js/modules/es.array.filter.js");
require("core-js/modules/es.object.to-string.js");
var React = _interopRequireWildcard(require("react"));
var _actions = require("./actions");
var _reactBootstrap = require("react-bootstrap");
var _authorCreditSection = _interopRequireDefault(require("../author-credit-editor/author-credit-section"));
var _reactFontawesome = require("@fortawesome/react-fontawesome");
var _reactSelect = _interopRequireDefault(require("react-select"));
var _reactRedux = require("react-redux");
var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/*
 * Copyright (C) 2017  Ben Ockmore
 *
 * 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 EditionGroupSection component contains input fields
 * specific to the editionGroup entity. The intention is that this component is
 * rendered as a modular section within the entity editor.
 *
 * @param {Object} props - The properties passed to the component.
 * @param {Array} props.editionGroupTypes - The list of possible types for a
 *        editionGroup.
 * @param {number} props.typeValue - The type currently selected for the
 *        editionGroup.
 * @param {Function} props.onTypeChange - A function to be called when
 *        a different publisher type is selected.
 * @returns {ReactElement} React element containing the rendered
 *          EditionGroupSection.
 */
function EditionGroupSection(_ref) {
  var editionGroupTypes = _ref.editionGroupTypes,
    typeValue = _ref.typeValue,
    isUnifiedForm = _ref.isUnifiedForm,
    isLeftAlign = _ref.isLeftAlign,
    onTypeChange = _ref.onTypeChange;
  var editionGroupTypesForDisplay = editionGroupTypes.map(function (type) {
    return {
      label: type.label,
      value: type.id
    };
  });
  var typeOption = editionGroupTypesForDisplay.filter(function (el) {
    return el.value === typeValue;
  });
  var tooltip = /*#__PURE__*/React.createElement(_reactBootstrap.Tooltip, null, "Physical format of the Edition Group");
  var heading = /*#__PURE__*/React.createElement("h2", null, "What else do you know about the Edition Group?");
  var lgCol = {
    offset: 3,
    span: 6
  };
  if (isUnifiedForm) {
    lgCol.offset = 0;
  }
  return /*#__PURE__*/React.createElement("div", null, !isUnifiedForm && heading, /*#__PURE__*/React.createElement(_authorCreditSection.default, {
    isLeftAlign: isLeftAlign,
    type: "editionGroup"
  }), /*#__PURE__*/React.createElement("p", {
    className: "text-muted"
  }, "All fields optional \u2014 leave something blank if you don\u2019t know it"), /*#__PURE__*/React.createElement(_reactBootstrap.Row, null, /*#__PURE__*/React.createElement(_reactBootstrap.Col, {
    lg: lgCol
  }, /*#__PURE__*/React.createElement(_reactBootstrap.Form.Group, null, /*#__PURE__*/React.createElement(_reactBootstrap.Form.Label, null, "Type", /*#__PURE__*/React.createElement(_reactBootstrap.OverlayTrigger, {
    delay: 50,
    overlay: tooltip
  }, /*#__PURE__*/React.createElement(_reactFontawesome.FontAwesomeIcon, {
    className: "margin-left-0-5",
    icon: _freeSolidSvgIcons.faQuestionCircle
  }))), /*#__PURE__*/React.createElement(_reactSelect.default, {
    isClearable: true,
    classNamePrefix: "react-select",
    instanceId: "editionGroupType",
    options: editionGroupTypesForDisplay,
    value: typeOption,
    onChange: onTypeChange
  })))));
}
EditionGroupSection.displayName = 'EditionGroupSection';
EditionGroupSection.defaultProps = {
  isLeftAlign: false,
  isUnifiedForm: false
};
function mapStateToProps(rootState) {
  var state = rootState.get('editionGroupSection');
  return {
    typeValue: state.get('type')
  };
}
function mapDispatchToProps(dispatch) {
  return {
    onTypeChange: function onTypeChange(value) {
      return dispatch((0, _actions.updateType)(value && value.value));
    }
  };
}
var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(EditionGroupSection);
exports.default = _default;
//# sourceMappingURL=edition-group-section.js.map