"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.object.to-string.js");
require("core-js/modules/web.dom-collections.for-each.js");
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _isNil3 = _interopRequireDefault(require("lodash/isNil"));
var _find3 = _interopRequireDefault(require("lodash/find"));
var React = _interopRequireWildcard(require("react"));
var _actions = require("./actions");
var _actions2 = require("../author-credit-editor/actions");
var _editionTable = _interopRequireDefault(require("../../components/pages/entities/edition-table"));
var _mergeField = _interopRequireDefault(require("../common/merge-field"));
var _entity = require("../../helpers/entity");
var _reactRedux = require("react-redux");
var _utils = require("../../helpers/utils");
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) 2019 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 EditionGroupSectionMerge component contains input fields
* specific to merging editionGroup entities. 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 {number} props.typeValue - The type currently selected for the
* editionGroup.
* @param {Array} props.mergingEntities - The list of entities being merged
* @param {Function} props.onTypeChange - A function to be called when
* a different publisher type is selected.
* @returns {ReactElement} React element containing the rendered
* EditionGroupSectionMerge.
*/
function EditionGroupSectionMerge(_ref) {
var authorCreditValue = _ref.authorCreditValue,
typeValue = _ref.typeValue,
mergingEntities = _ref.mergingEntities,
onAuthorCreditChange = _ref.onAuthorCreditChange,
onTypeChange = _ref.onTypeChange;
var authorCreditOptions = [];
var typeOptions = [];
var editions = [];
mergingEntities.forEach(function (entity) {
var authorCredit = !(0, _isNil3.default)(entity.authorCredit) && {
label: (0, _entity.authorCreditToString)(entity.authorCredit),
value: entity.authorCredit
};
if (authorCredit && !(0, _find3.default)(authorCreditOptions, ['value.id', authorCredit.value.id])) {
authorCreditOptions.push(authorCredit);
}
var typeOption = entity.editionGroupType && {
label: entity.editionGroupType.label,
value: entity.editionGroupType.id
};
if (typeOption && !(0, _find3.default)(typeOptions, ['value', typeOption.value])) {
typeOptions.push(typeOption);
}
editions.push.apply(editions, (0, _toConsumableArray2.default)(entity.editions));
});
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_mergeField.default, {
currentValue: authorCreditValue,
label: "Author Credit",
options: authorCreditOptions,
valueRenderer: _entity.authorCreditToString,
onChange: onAuthorCreditChange
}), /*#__PURE__*/React.createElement(_mergeField.default, {
currentValue: typeValue,
label: "Type",
options: typeOptions,
onChange: onTypeChange
}), /*#__PURE__*/React.createElement(_editionTable.default, {
editions: editions,
entity: mergingEntities[0],
showAdd: false
}));
}
EditionGroupSectionMerge.displayName = 'EditionGroupSectionMerge';
function mapStateToProps(rootState) {
var state = rootState.get('editionGroupSection');
var authorCredit = rootState.get('authorCredit');
return {
authorCreditValue: (0, _utils.convertMapToObject)(authorCredit),
typeValue: state.get('type')
};
}
function mapDispatchToProps(dispatch) {
return {
onAuthorCreditChange: function onAuthorCreditChange(selectedAuthorCredit) {
dispatch((0, _actions2.updateAuthorCredit)(selectedAuthorCredit));
},
onTypeChange: function onTypeChange(value) {
return dispatch((0, _actions.updateType)(value));
}
};
}
var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(EditionGroupSectionMerge);
exports.default = _default;
//# sourceMappingURL=edition-group-section-merge.js.map