client/entity-editor/alias-editor/alias-row-merge.js

"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _reactRedux = require("react-redux");
var _actions = require("./actions");
/*
 * 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 AliasRowMerge component renders a single Row containing
 * several input fields, allowing the user to set the name, sort name, language
 * and primary flag for an alias in the AliasEditor. A button is also included
 * to remove the alias from the editor.
 *
 * @param {Object} props - The properties passed to the component.
 * @param {number} props.languageValue - The ID of the language currently
 *        selected.
 * @param {Array} props.languageOptions - The list of possible languages for an
 *        alias.
 * @param {string} props.nameValue - The name currently set for this alias.
 * @param {string} props.sortNameValue - The sort name currently set for this
 *        alias.
 * @param {string} props.primaryChecked - Whether or not the primary checkbox
 *        is checked.
 * @param {Function} props.onRemoveButtonClick - A function to be called when
 *        the button to remove the alias is clicked.
 * @returns {ReactElement} React element containing the rendered AliasRowMerge.
 */
var AliasRowMerge = function AliasRowMerge(_ref) {
  var languageOptions = _ref.languageOptions,
    languageValue = _ref.languageValue,
    nameValue = _ref.nameValue,
    sortNameValue = _ref.sortNameValue,
    primaryChecked = _ref.primaryChecked;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: "margin-bottom-1"
  }, nameValue, " ", /*#__PURE__*/_react.default.createElement("small", null, "(", sortNameValue, ")"), "\xA0", /*#__PURE__*/_react.default.createElement("small", {
    className: "text-muted"
  }, primaryChecked && 'Primary', " ", languageOptions[languageValue]));
};
AliasRowMerge.displayName = 'AliasEditor.AliasRowMerge';
AliasRowMerge.propTypes = {
  languageOptions: _propTypes.default.object.isRequired,
  languageValue: _propTypes.default.number,
  nameValue: _propTypes.default.string.isRequired,
  primaryChecked: _propTypes.default.bool.isRequired,
  sortNameValue: _propTypes.default.string.isRequired
};
AliasRowMerge.defaultProps = {
  languageValue: null
};
function mapDispatchToProps(dispatch, _ref2) {
  var index = _ref2.index;
  return {
    onRemoveButtonClick: function onRemoveButtonClick() {
      return dispatch((0, _actions.removeAliasRow)(index));
    }
  };
}
function mapStateToProps(rootState, _ref3) {
  var index = _ref3.index;
  var state = rootState.get('aliasEditor');
  return {
    languageValue: state.getIn([index, 'language']),
    nameValue: state.getIn([index, 'name']),
    primaryChecked: state.getIn([index, 'primary']),
    sortNameValue: state.getIn([index, 'sortName'])
  };
}
var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(AliasRowMerge);
exports.default = _default;
//# sourceMappingURL=alias-row-merge.js.map