"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 _publisher = require("../validators/publisher");
var _newDateField = _interopRequireDefault(require("../common/new-date-field"));
var _entitySearchFieldOption = _interopRequireDefault(require("../common/entity-search-field-option"));
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) 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 PublisherSection component contains input fields
* specific to the publisher 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 {Map<string, any>} props.areaValue - The area currently set for this
* publisher.
* @param {string} props.beginDateValue - The begin date currently set for
* this publisher.
* @param {string} props.endDateValue - The end date currently set for this
* publisher.
* @param {boolean} props.endedChecked - Whether or not the ended checkbox
* is checked.
* @param {Array} props.publisherTypes - The list of possible types for a
* publisher.
* @param {number} props.typeValue - The ID of the type currently selected for
* the publisher.
* @param {Function} props.onAreaChange - A function to be called when a
* different area is selected.
* @param {Function} props.onBeginDateChange - A function to be called when
* the begin date is changed.
* @param {Function} props.onEndDateChange - A function to be called when
* the end date is changed.
* @param {Function} props.onEndedChange - A function to be called when
* the ended checkbox is toggled.
* @param {Function} props.onTypeChange - A function to be called when
* a different publisher type is selected.
* @returns {ReactElement} React element containing the rendered
* PublisherSection.
*/
function PublisherSection(_ref) {
var areaValue = _ref.areaValue,
beginDateValue = _ref.beginDateValue,
endDateValue = _ref.endDateValue,
endedChecked = _ref.endedChecked,
publisherTypes = _ref.publisherTypes,
typeValue = _ref.typeValue,
isUnifiedForm = _ref.isUnifiedForm,
onAreaChange = _ref.onAreaChange,
onBeginDateChange = _ref.onBeginDateChange,
onEndDateChange = _ref.onEndDateChange,
onEndedChange = _ref.onEndedChange,
onTypeChange = _ref.onTypeChange;
var publisherTypesForDisplay = publisherTypes.map(function (type) {
return {
label: type.label,
value: type.id
};
});
var typeOption = publisherTypesForDisplay.filter(function (el) {
return el.value === typeValue;
});
var _validatePublisherSec = (0, _publisher.validatePublisherSectionBeginDate)(beginDateValue),
isValidBeginDate = _validatePublisherSec.isValid,
errorMessageBeginDate = _validatePublisherSec.errorMessage;
var _validatePublisherSec2 = (0, _publisher.validatePublisherSectionEndDate)(beginDateValue, endDateValue, endedChecked),
isValidEndDate = _validatePublisherSec2.isValid,
errorMessageEndDate = _validatePublisherSec2.errorMessage;
var heading = /*#__PURE__*/React.createElement("h2", null, "What else do you know about the Publisher?");
var lgCol = {
offset: 3,
span: 6
};
if (isUnifiedForm) {
lgCol.offset = 0;
}
return /*#__PURE__*/React.createElement("div", null, !isUnifiedForm && heading, /*#__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(_reactSelect.default, {
isClearable: true,
classNamePrefix: "react-select",
instanceId: "publisherType",
options: publisherTypesForDisplay,
value: typeOption,
onChange: onTypeChange
})))), /*#__PURE__*/React.createElement(_reactBootstrap.Row, null, /*#__PURE__*/React.createElement(_reactBootstrap.Col, {
lg: lgCol
}, /*#__PURE__*/React.createElement(_entitySearchFieldOption.default, {
instanceId: "area",
label: "Area",
tooltipText: "Country or place the publisher is registered in",
type: "area",
value: areaValue,
onChange: onAreaChange
}))), /*#__PURE__*/React.createElement(_reactBootstrap.Row, null, /*#__PURE__*/React.createElement(_reactBootstrap.Col, {
lg: lgCol
}, /*#__PURE__*/React.createElement(_newDateField.default, {
show: true,
defaultValue: beginDateValue,
empty: (0, _utils.isNullDate)(beginDateValue),
error: !isValidBeginDate,
errorMessage: errorMessageBeginDate,
label: "Date Founded",
placeholder: "YYYY-MM-DD",
onChangeDate: onBeginDateChange
}))), /*#__PURE__*/React.createElement("div", {
className: "".concat(!isUnifiedForm && 'text-center')
}, /*#__PURE__*/React.createElement(_reactBootstrap.Form.Check, {
defaultChecked: endedChecked,
label: "Dissolved?",
type: "checkbox",
onChange: onEndedChange
})), endedChecked && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_reactBootstrap.Row, null, /*#__PURE__*/React.createElement(_reactBootstrap.Col, {
lg: lgCol
}, /*#__PURE__*/React.createElement(_newDateField.default, {
show: true,
defaultValue: endDateValue,
empty: (0, _utils.isNullDate)(endDateValue),
error: !isValidEndDate,
errorMessage: errorMessageEndDate,
label: "Date Dissolved",
placeholder: "YYYY-MM-DD",
onChangeDate: onEndDateChange
})))));
}
PublisherSection.displayName = 'PublisherSection';
PublisherSection.defaultProps = {
isUnifiedForm: false
};
function mapStateToProps(rootState) {
var state = rootState.get('publisherSection');
return {
areaValue: state.get('area'),
beginDateValue: state.get('beginDate'),
endDateValue: state.get('endDate'),
endedChecked: state.get('ended'),
typeValue: state.get('type')
};
}
function mapDispatchToProps(dispatch) {
return {
onAreaChange: function onAreaChange(value) {
return dispatch((0, _actions.updateArea)(value));
},
onBeginDateChange: function onBeginDateChange(beginDate) {
dispatch((0, _actions.debouncedUpdateBeginDate)(beginDate));
},
onEndDateChange: function onEndDateChange(endDate) {
return dispatch((0, _actions.debouncedUpdateEndDate)(endDate));
},
onEndedChange: function onEndedChange(event) {
return dispatch((0, _actions.updateEnded)(event.target.checked));
},
onTypeChange: function onTypeChange(value) {
return dispatch((0, _actions.updateType)(value && value.value));
}
};
}
var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(PublisherSection);
exports.default = _default;
//# sourceMappingURL=publisher-section.js.map