"use strict";
require("core-js/modules/es.object.keys.js");
require("core-js/modules/es.symbol.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
require("core-js/modules/es.object.get-own-property-descriptors.js");
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");
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.array.filter.js");
require("core-js/modules/es.array.map.js");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _find3 = _interopRequireDefault(require("lodash/find"));
var React = _interopRequireWildcard(require("react"));
var _actions = require("./actions");
var _utils = require("../../helpers/utils");
var _mergeField = _interopRequireDefault(require("../common/merge-field"));
var _reactRedux = require("react-redux");
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; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } /*
* Copyright (C) 2021 Akash Gupta
*
* 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 SeriesSectionMerge component contains input fields
* specific to merging series 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.orderTypeValue - The order type currently selected for
* the series.
* @param {string} props.seriesTypeValue - The entity type currently selected for
* the series.
* @param {Array} props.mergingEntities - The list of entities being merged
* @param {Function} props.onOrderTypeChange - A function to be called when
* a different series order type is selected.
* @param {Function} props.onSeriesTypeChange - A function to be called when
* a different series entity type is selected.
* @returns {ReactElement} React element containing the rendered
* SeriesSectionMerge.
*/
function SeriesSectionMerge(_ref) {
var _propsForTable;
var orderTypeValue = _ref.orderTypeValue,
seriesTypeValue = _ref.seriesTypeValue,
mergingEntities = _ref.mergingEntities,
onOrderTypeChange = _ref.onOrderTypeChange,
onSeriesTypeChange = _ref.onSeriesTypeChange;
var seriesOrderingTypeOptions = [];
var seriesTypeOptions = [];
var relationships = [];
mergingEntities.forEach(function (entity) {
var seriesOrderingTypeOption = entity.seriesOrderingType && {
label: entity.seriesOrderingType.label,
value: entity.seriesOrderingType.id
};
if (seriesOrderingTypeOption && !(0, _find3.default)(seriesOrderingTypeOptions, ['value', seriesOrderingTypeOption.value])) {
seriesOrderingTypeOptions.push(seriesOrderingTypeOption);
}
var seriesTypeOption = entity.entityType;
if (seriesTypeOption && !(0, _find3.default)(seriesTypeOptions, ['value', seriesTypeOption])) {
seriesTypeOptions.push({
label: seriesTypeOption,
value: seriesTypeOption
});
}
relationships.push.apply(relationships, (0, _toConsumableArray2.default)(entity.relationships));
});
// Filter out series items from relationships
var seriesItems = relationships.filter(function (relationship) {
return relationship.typeId > 69 && relationship.typeId < 75;
});
var formattedSeriesItems = seriesItems.map(function (item) {
return _objectSpread(_objectSpread({}, item.source), {}, {
displayNumber: true,
number: item.number,
position: item.position
});
});
var EntityTable = (0, _utils.getEntityTable)(seriesTypeValue);
var entityKey = (0, _utils.getEntityKey)(seriesTypeValue);
var propsForTable = (_propsForTable = {}, (0, _defineProperty2.default)(_propsForTable, entityKey, formattedSeriesItems), (0, _defineProperty2.default)(_propsForTable, "showAdd", false), (0, _defineProperty2.default)(_propsForTable, "showAddedAtColumn", false), (0, _defineProperty2.default)(_propsForTable, "showCheckboxes", false), _propsForTable);
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_mergeField.default, {
currentValue: orderTypeValue,
label: "Ordering Type",
options: seriesOrderingTypeOptions,
onChange: onOrderTypeChange
}), /*#__PURE__*/React.createElement(_mergeField.default, {
currentValue: seriesTypeValue,
label: "Series Type",
options: seriesTypeOptions,
onChange: onSeriesTypeChange
}), /*#__PURE__*/React.createElement(EntityTable, propsForTable));
}
SeriesSectionMerge.displayName = 'SeriesSectionMerge';
function mapStateToProps(rootState) {
var state = rootState.get('seriesSection');
return {
orderTypeValue: state.get('orderType'),
seriesTypeValue: state.get('seriesType')
};
}
function mapDispatchToProps(dispatch) {
return {
onOrderTypeChange: function onOrderTypeChange(value) {
return dispatch((0, _actions.updateOrderType)(value));
},
onSeriesTypeChange: function onSeriesTypeChange(value) {
return dispatch((0, _actions.updateSeriesType)(value));
}
};
}
var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(SeriesSectionMerge);
exports.default = _default;
//# sourceMappingURL=series-section-merge.js.map