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

"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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.function.name.js");
require("core-js/modules/es.promise.js");
require("core-js/modules/es.array.map.js");
require("core-js/modules/es.array.filter.js");
var _aliasRowMerge = _interopRequireDefault(require("./alias-row-merge"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _reactRedux = require("react-redux");
/*
 * 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 AliasEditorMerge component contains a number of AliasRow
 * elements, and renders these inside a modal, which appears when the show
 * property of the component is set.
 *
 * @param {Object} props - The properties passed to the component.
 * @param {Array} props.aliases - The list of aliases to be rendered in the
 *        editor.
 * @param {Array} props.languageOptions - The list of possible languages for an
 *        alias.
 * @returns {ReactElement} React element containing the rendered AliasEditorMerge.
 */
var AliasEditorMerge = function AliasEditorMerge(_ref) {
  var aliases = _ref.aliases,
    languageOptions = _ref.languageOptions;
  var languageOptionsForDisplay = {};
  languageOptions.forEach(function (language) {
    return languageOptionsForDisplay[language.id] = language.name;
  });
  var noAliasesTextClass = (0, _classnames.default)('text-center', {
    'd-none': aliases.size
  });
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("h2", null, "Aliases"), /*#__PURE__*/_react.default.createElement("div", {
    className: noAliasesTextClass
  }, /*#__PURE__*/_react.default.createElement("p", {
    className: "text-muted"
  }, "This entity has no aliases")), aliases.map(function (alias, rowId) {
    return /*#__PURE__*/_react.default.createElement(_aliasRowMerge.default, {
      index: rowId
      // eslint-disable-next-line react/no-array-index-key
      ,
      key: rowId,
      languageOptions: languageOptionsForDisplay
    });
  }).toArray());
};
AliasEditorMerge.displayName = 'AliasEditorMerge';
AliasEditorMerge.propTypes = {
  aliases: _propTypes.default.object.isRequired,
  languageOptions: _propTypes.default.array.isRequired
};
function mapStateToProps(rootState) {
  var nameSection = rootState.get('nameSection');
  var aliases = rootState.get('aliasEditor');

  /** Dynamically filter out aliases that are different
   * from the attributes selected in the nameSection
   * */
  var filteredAliases = aliases.filter(function (alias) {
    return alias.get('name') !== nameSection.get('name') || alias.get('language') !== nameSection.get('language') || alias.get('sortName') !== nameSection.get('sortName');
  });
  return {
    aliases: filteredAliases
  };
}
var _default = (0, _reactRedux.connect)(mapStateToProps)(AliasEditorMerge);
exports.default = _default;
//# sourceMappingURL=alias-editor-merge.js.map