client/entity-editor/entity-merge.js

"use strict";

require("core-js/modules/es.object.keys.js");
require("core-js/modules/es.symbol.js");
require("core-js/modules/es.array.filter.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
require("core-js/modules/web.dom-collections.for-each.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.array.map.js");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _get2 = _interopRequireDefault(require("lodash/get"));
var _values2 = _interopRequireDefault(require("lodash/values"));
var React = _interopRequireWildcard(require("react"));
var _reactBootstrap = require("react-bootstrap");
var _aliasEditorMerge = _interopRequireDefault(require("./alias-editor/alias-editor-merge"));
var _annotationSection = _interopRequireDefault(require("./annotation-section/annotation-section"));
var _entity = _interopRequireDefault(require("./common/entity"));
var _identifiers = _interopRequireDefault(require("../components/pages/entities/identifiers"));
var _reactFontawesome = require("@fortawesome/react-fontawesome");
var _nameSectionMerge = _interopRequireDefault(require("./name-section/name-section-merge"));
var _relationshipSection = _interopRequireDefault(require("./relationship-editor/relationship-section"));
var _submissionSection = _interopRequireDefault(require("./submission-section/submission-section"));
var _reactRedux = require("react-redux");
var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
var _utils = require("../../common/helpers/utils");
var _actions = require("./submission-section/actions");
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) 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. Renders all of the sections of the entity editing form.
 *
 * @param {Object} props - The properties passed to the component.
 * @param {React.Node} props.children - The child content to wrap with this
 *        entity editor form.
 * @param {Array} props.mergingEntities - An array of entities that are being merge
 * @param {boolean} props.identifierSet - Concatenated identifiers from entities in merging
 * @param {boolean} props.identifierTypes - possible identifier types for this entity type
 * @param {string} props.subheading - Subheading at the top of the html page
 * @param {Function} props.onSubmit - A function to be called when the
 *        submit button is clicked.
 * @returns {ReactElement} React element containing the rendered EntityMerge.
 */
var EntityMerge = function EntityMerge(props) {
  var children = props.children,
    mergingEntities = props.mergingEntities,
    identifierSet = props.identifierSet,
    identifierTypes = props.identifierTypes,
    subheading = props.subheading,
    onSubmit = props.onSubmit;
  var identifiers = (0, _values2.default)(identifierSet.toJS()) || [];
  return /*#__PURE__*/React.createElement("form", {
    onSubmit: onSubmit
  }, /*#__PURE__*/React.createElement(_reactBootstrap.Card, null, /*#__PURE__*/React.createElement(_reactBootstrap.Card.Header, {
    as: "h4"
  }, /*#__PURE__*/React.createElement("p", null, subheading), /*#__PURE__*/React.createElement("div", null, mergingEntities.map(function (entity, index) {
    var entityForDisplay = {
      link: (0, _utils.getEntityLink)({
        bbid: entity.bbid,
        type: entity.type
      }),
      text: (0, _get2.default)(entity, ['defaultAlias', 'name']),
      type: entity.type,
      unnamedText: '(unnamed)'
    };
    var isNotLast = index < mergingEntities.length - 1;
    return /*#__PURE__*/React.createElement("span", {
      key: entity.bbid
    }, /*#__PURE__*/React.createElement(_entity.default, entityForDisplay), isNotLast && /*#__PURE__*/React.createElement(_reactFontawesome.FontAwesomeIcon, {
      className: "margin-sides-d5",
      icon: _freeSolidSvgIcons.faAngleDoubleLeft
    }));
  }))), /*#__PURE__*/React.createElement(_reactBootstrap.Card.Body, null, /*#__PURE__*/React.createElement("p", {
    className: "alert alert-info"
  }, "You are merging into entity ", mergingEntities[0].bbid, ". If you want to merge into another entity instead, you can select the correct entity in the merge queue at the bottom of the page and click the ", /*#__PURE__*/React.createElement("i", null, "Merge into selected entity"), " button again. This will reload the page with the new merge target selected."), /*#__PURE__*/React.createElement("p", {
    className: "text-muted"
  }, "Select and review the data to merge. For further modifications, edit the resulting merged entity."), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_reactBootstrap.Row, null, /*#__PURE__*/React.createElement(_reactBootstrap.Col, {
    lg: {
      offset: 1,
      span: 5
    }
  }, /*#__PURE__*/React.createElement(_nameSectionMerge.default, props)), /*#__PURE__*/React.createElement(_reactBootstrap.Col, {
    lg: {
      offset: 1,
      span: 5
    }
  }, /*#__PURE__*/React.createElement(_aliasEditorMerge.default, props))), /*#__PURE__*/React.createElement(_reactBootstrap.Row, null, /*#__PURE__*/React.createElement(_reactBootstrap.Col, {
    lg: {
      offset: 1,
      span: 5
    }
  }, /*#__PURE__*/React.cloneElement(React.Children.only(children), _objectSpread({}, props)))), /*#__PURE__*/React.createElement(_reactBootstrap.Row, null, /*#__PURE__*/React.createElement(_reactBootstrap.Col, {
    lg: 8
  }, /*#__PURE__*/React.createElement(_relationshipSection.default, props)), /*#__PURE__*/React.createElement(_reactBootstrap.Col, {
    lg: 4
  }, /*#__PURE__*/React.createElement(_identifiers.default, {
    identifierTypes: identifierTypes,
    identifiers: identifiers
  }))), /*#__PURE__*/React.createElement(_annotationSection.default, props))), /*#__PURE__*/React.createElement(_reactBootstrap.Card.Footer, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_submissionSection.default, props)))));
};
EntityMerge.displayName = 'EntityMerge';
function mapStateToProps(rootState) {
  return {
    identifierSet: rootState.get('identifierEditor', {})
  };
}
function mapDispatchToProps(dispatch, _ref) {
  var submissionUrl = _ref.submissionUrl;
  return {
    onSubmit: function onSubmit(event) {
      event.preventDefault();
      dispatch((0, _actions.submit)(submissionUrl));
    }
  };
}
var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(EntityMerge);
exports.default = _default;
//# sourceMappingURL=entity-merge.js.map