"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");
require("core-js/modules/es.parse-int.js");
var _get2 = _interopRequireDefault(require("lodash/get"));
var _find2 = _interopRequireDefault(require("lodash/find"));
var _isNil2 = _interopRequireDefault(require("lodash/isNil"));
var React = _interopRequireWildcard(require("react"));
var _actions = require("./actions");
var _actions2 = require("../author-credit-editor/actions");
var _entity = require("../../helpers/entity");
var _entitySelect = _interopRequireDefault(require("../common/entity-select"));
var _reactBootstrap = require("react-bootstrap");
var _linkedEntitySelect = _interopRequireDefault(require("../common/linked-entity-select"));
var _mergeField = _interopRequireDefault(require("../common/merge-field"));
var _reactSelect = _interopRequireDefault(require("react-select"));
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 EditionSectionMerge component contains input fields
* specific to the edition 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.
* depthValue
* @param {number} props.formatValue - The ID of the format currently selected
* for the edition.
* heightValue
* languageValues
* mergingEntities
* onDepthChange
* @param {Function} props.onFormatChange - A function to be called when
* a different edition format is selected.
* onHeightChange,
onReleaseDateChange,
onPagesChange,
onEditionGroupChange,
onPublisherChange,
* @param {Function} props.onStatusChange - A function to be called when
* a different edition status is selected.
* onWeightChange,
onWidthChange,
pagesValue,
editionGroupValue,
publisherValue,
releaseDateValue,
* @param {number} props.statusValue - The ID of the status currently selected
* for the edition.
weightValue,
widthValue
* @returns {ReactElement} React element containing the rendered EditionSectionMerge.
*/
function EditionSectionMerge(_ref) {
var authorCreditValue = _ref.authorCreditValue,
depthValue = _ref.depthValue,
formatValue = _ref.formatValue,
heightValue = _ref.heightValue,
languageValues = _ref.languageValues,
mergingEntities = _ref.mergingEntities,
onAuthorCreditChange = _ref.onAuthorCreditChange,
onDepthChange = _ref.onDepthChange,
onFormatChange = _ref.onFormatChange,
onHeightChange = _ref.onHeightChange,
onReleaseDateChange = _ref.onReleaseDateChange,
onPagesChange = _ref.onPagesChange,
onEditionGroupChange = _ref.onEditionGroupChange,
onPublisherChange = _ref.onPublisherChange,
onStatusChange = _ref.onStatusChange,
onWeightChange = _ref.onWeightChange,
onWidthChange = _ref.onWidthChange,
pagesValue = _ref.pagesValue,
editionGroupValue = _ref.editionGroupValue,
publisherValue = _ref.publisherValue,
releaseDateValue = _ref.releaseDateValue,
statusValue = _ref.statusValue,
weightValue = _ref.weightValue,
widthValue = _ref.widthValue;
var editionGroupOptions = [];
var authorCreditOptions = [];
var releaseDateOptions = [];
var depthOptions = [];
var formatOptions = [];
var heightOptions = [];
var pagesOptions = [];
var publisherOptions = [];
var statusOptions = [];
var weightOptions = [];
var widthOptions = [];
mergingEntities.forEach(function (entity) {
var depth = !(0, _isNil2.default)(entity.depth) && {
label: entity.depth,
value: entity.depth
};
if (depth && !(0, _find2.default)(depthOptions, ['value', depth.value])) {
depthOptions.push(depth);
}
var editionGroup = !(0, _isNil2.default)(entity.editionGroup) && (0, _entity.entityToOption)(entity.editionGroup);
var editionGroupOption = editionGroup && {
label: editionGroup.text,
value: editionGroup
};
if (editionGroupOption && !(0, _find2.default)(editionGroupOptions, ['value.id', editionGroupOption.value.id])) {
editionGroupOptions.push(editionGroupOption);
}
var authorCredit = !(0, _isNil2.default)(entity.authorCredit) && {
label: (0, _entity.authorCreditToString)(entity.authorCredit),
value: entity.authorCredit
};
if (authorCredit && !(0, _find2.default)(authorCreditOptions, ['value.id', authorCredit.value.id])) {
authorCreditOptions.push(authorCredit);
}
var format = entity.editionFormat && {
label: entity.editionFormat.label,
value: entity.editionFormat.id
};
if (format && !(0, _find2.default)(formatOptions, ['value', format.value])) {
formatOptions.push(format);
}
var height = !(0, _isNil2.default)(entity.height) && {
label: entity.height,
value: entity.height
};
if (height && !(0, _find2.default)(heightOptions, ['value', height.value])) {
heightOptions.push(height);
}
var pages = !(0, _isNil2.default)(entity.pages) && {
label: entity.pages,
value: entity.pages
};
if (pages && !(0, _find2.default)(pagesOptions, ['value', pages.value])) {
pagesOptions.push(pages);
}
var publisher = (0, _entity.entityToOption)((0, _get2.default)(entity, 'publisherSet.publishers[0]'));
var publisherOption = publisher && {
label: publisher.text,
value: publisher
};
if (publisherOption && !(0, _find2.default)(publisherOptions, ['value.id', publisherOption.value.id])) {
publisherOptions.push(publisherOption);
}
var releaseEventDate = (0, _get2.default)(entity, 'releaseEventSet.releaseEvents[0].date');
var releaseDate = !(0, _isNil2.default)(releaseEventDate) && (0, _entity.transformISODateForSelect)(releaseEventDate);
if (releaseDate && !(0, _find2.default)(releaseDateOptions, ['value', releaseDate.value])) {
releaseDateOptions.push(releaseDate);
}
var statusOption = entity.editionStatus && {
label: entity.editionStatus.label,
value: entity.editionStatus.id
};
if (statusOption && !(0, _find2.default)(statusOptions, ['value', statusOption.value])) {
statusOptions.push(statusOption);
}
var weight = !(0, _isNil2.default)(entity.weight) && {
label: entity.weight,
value: entity.weight
};
if (weight && !(0, _find2.default)(weightOptions, ['value', weight.value])) {
weightOptions.push(weight);
}
var width = !(0, _isNil2.default)(entity.width) && {
label: entity.width,
value: entity.width
};
if (width && !(0, _find2.default)(widthOptions, ['value', width.value])) {
widthOptions.push(width);
}
});
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, {
components: {
Option: _linkedEntitySelect.default,
SingleValue: _entitySelect.default
},
currentValue: editionGroupValue,
label: "Edition Group",
options: editionGroupOptions,
onChange: onEditionGroupChange
}), /*#__PURE__*/React.createElement(_mergeField.default, {
currentValue: releaseDateValue,
label: "Release date",
options: releaseDateOptions,
onChange: onReleaseDateChange
}), /*#__PURE__*/React.createElement(_mergeField.default, {
components: {
Option: _linkedEntitySelect.default,
SingleValue: _entitySelect.default
},
currentValue: publisherValue,
label: "Publisher",
options: publisherOptions,
onChange: onPublisherChange
}), /*#__PURE__*/React.createElement(_mergeField.default, {
currentValue: formatValue,
label: "Format",
options: formatOptions,
onChange: onFormatChange
}), /*#__PURE__*/React.createElement(_mergeField.default, {
currentValue: statusValue,
label: "Status",
options: statusOptions,
onChange: onStatusChange
}), /*#__PURE__*/React.createElement(_mergeField.default, {
currentValue: depthValue,
label: "Depth",
options: depthOptions,
onChange: onDepthChange
}), /*#__PURE__*/React.createElement(_mergeField.default, {
currentValue: widthValue,
label: "Width",
options: widthOptions,
onChange: onWidthChange
}), /*#__PURE__*/React.createElement(_mergeField.default, {
currentValue: heightValue,
label: "Height",
options: heightOptions,
onChange: onHeightChange
}), /*#__PURE__*/React.createElement(_mergeField.default, {
currentValue: pagesValue,
label: "Pages",
options: pagesOptions,
onChange: onPagesChange
}), /*#__PURE__*/React.createElement(_mergeField.default, {
currentValue: weightValue,
label: "Weight",
options: weightOptions,
onChange: onWeightChange
}), /*#__PURE__*/React.createElement(_reactBootstrap.Form.Group, null, /*#__PURE__*/React.createElement(_reactBootstrap.Form.Label, null, "Languages"), /*#__PURE__*/React.createElement(_reactSelect.default, {
isDisabled: true,
isMulti: true,
classNamePrefix: "react-select",
instanceId: "languages",
placeholder: "No languages",
value: languageValues
})));
}
EditionSectionMerge.displayName = 'EditionSectionMerge';
function mapStateToProps(rootState) {
var state = rootState.get('editionSection');
var authorCredit = rootState.get('authorCredit');
return {
authorCreditValue: (0, _utils.convertMapToObject)(authorCredit),
depthValue: state.get('depth'),
editionGroupValue: (0, _utils.convertMapToObject)(state.get('editionGroup')),
formatValue: state.get('format'),
heightValue: state.get('height'),
languageValues: (0, _utils.convertMapToObject)(state.get('languages')),
pagesValue: state.get('pages'),
publisherValue: (0, _utils.convertMapToObject)(state.get('publisher')),
releaseDateValue: state.get('releaseDate'),
statusValue: state.get('status'),
weightValue: state.get('weight'),
widthValue: state.get('width')
};
}
function mapDispatchToProps(dispatch) {
return {
onAuthorCreditChange: function onAuthorCreditChange(selectedAuthorCredit) {
dispatch((0, _actions2.updateAuthorCredit)(selectedAuthorCredit));
},
onDepthChange: function onDepthChange(event) {
return dispatch((0, _actions.debouncedUpdateDepth)(event.target.value ? parseInt(event.target.value, 10) : null));
},
onEditionGroupChange: function onEditionGroupChange(value) {
return dispatch((0, _actions.updateEditionGroup)(value));
},
onFormatChange: function onFormatChange(value) {
return dispatch((0, _actions.updateFormat)(value));
},
onHeightChange: function onHeightChange(event) {
return dispatch((0, _actions.debouncedUpdateHeight)(event.target.value ? parseInt(event.target.value, 10) : null));
},
onPagesChange: function onPagesChange(event) {
return dispatch((0, _actions.debouncedUpdatePages)(event.target.value ? parseInt(event.target.value, 10) : null));
},
onPublisherChange: function onPublisherChange(value) {
return dispatch((0, _actions.updatePublisher)(value));
},
onReleaseDateChange: function onReleaseDateChange(dateString) {
return dispatch((0, _actions.debouncedUpdateReleaseDate)(dateString));
},
onStatusChange: function onStatusChange(value) {
return dispatch((0, _actions.updateStatus)(value));
},
onWeightChange: function onWeightChange(event) {
return dispatch((0, _actions.debouncedUpdateWeight)(event.target.value ? parseInt(event.target.value, 10) : null));
},
onWidthChange: function onWidthChange(event) {
return dispatch((0, _actions.debouncedUpdateWidth)(event.target.value ? parseInt(event.target.value, 10) : null));
}
};
}
var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(EditionSectionMerge);
exports.default = _default;
//# sourceMappingURL=edition-section-merge.js.map