client/entity-editor/button-bar/button-bar.js

"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactBootstrap = require("react-bootstrap");
var _actions = require("./actions");
var _common = require("../validators/common");
var _aliasButton = _interopRequireDefault(require("./alias-button"));
var _identifierButton = _interopRequireDefault(require("./identifier-button"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _actions2 = require("../alias-editor/actions");
var _actions3 = require("../identifier-editor/actions");
var _reactRedux = require("react-redux");
/*
 * Copyright (C) 2016  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. This component renders three buttons in a horizontal
 * row allowing the user to open the AliasEditor (AliasButton), add a
 * disambiguation to the entity and open the IdentifierEditor
 * (IdentifierButton).
 *
 * @param {Object} props - The properties passed to the component.
 * @param {number} props.numAliases - The number of aliases present in
 *        the AliasEditor - passed to the AliasButton component.
 * @param {number} props.numIdentifiers - The number of identifiers present in
 *        the IdentifierEditor - passed to the IdentiferButton component.
 * @param {Function} props.onAliasButtonClick - A function to be called when the
 *        AliasButton is clicked.
 * @param {Function} props.onIdentifierButtonClick - A function to be called
 *        when the IdentifierButton is clicked.
 * @returns {ReactElement} React element containing the rendered ButtonBar.
 */
function ButtonBar(_ref) {
  var aliasesInvalid = _ref.aliasesInvalid,
    identifiersInvalid = _ref.identifiersInvalid,
    numAliases = _ref.numAliases,
    numIdentifiers = _ref.numIdentifiers,
    onAliasButtonClick = _ref.onAliasButtonClick,
    isUnifiedForm = _ref.isUnifiedForm,
    onIdentifierButtonClick = _ref.onIdentifierButtonClick;
  var className = isUnifiedForm ? 'text-right' : 'text-center';
  function renderAliasButton() {
    if (isUnifiedForm) {
      return null;
    }
    return /*#__PURE__*/_react.default.createElement(_reactBootstrap.Col, {
      className: className,
      lg: 6
    }, /*#__PURE__*/_react.default.createElement(_aliasButton.default, {
      aliasesInvalid: aliasesInvalid,
      numAliases: numAliases,
      onClick: onAliasButtonClick
    }));
  }
  var identifierEditorClass = "btn wrap".concat(!isUnifiedForm ? '' : ' btn-success');
  return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Row, {
    className: "margin-top-1"
  }, renderAliasButton(), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Col, {
    className: className,
    lg: 6
  }, /*#__PURE__*/_react.default.createElement(_identifierButton.default, {
    className: identifierEditorClass,
    identifiersInvalid: identifiersInvalid,
    isUnifiedForm: isUnifiedForm,
    numIdentifiers: numIdentifiers,
    onClick: onIdentifierButtonClick
  }))));
}
ButtonBar.displayName = 'ButtonBar';
ButtonBar.propTypes = {
  aliasesInvalid: _propTypes.default.bool.isRequired,
  identifiersInvalid: _propTypes.default.bool.isRequired,
  isUnifiedForm: _propTypes.default.bool,
  numAliases: _propTypes.default.number.isRequired,
  numIdentifiers: _propTypes.default.number.isRequired,
  onAliasButtonClick: _propTypes.default.func.isRequired,
  onIdentifierButtonClick: _propTypes.default.func.isRequired
};
ButtonBar.defaultProps = {
  isUnifiedForm: false
};
function mapStateToProps(rootState, _ref2) {
  var identifierTypes = _ref2.identifierTypes;
  return {
    aliasesInvalid: !(0, _common.validateAliases)(rootState.get('aliasEditor')),
    identifiersInvalid: !(0, _common.validateIdentifiers)(rootState.get('identifierEditor'), identifierTypes),
    numAliases: rootState.get('aliasEditor').size,
    numIdentifiers: rootState.get('identifierEditor').size
  };
}
function mapDispatchToProps(dispatch) {
  return {
    onAliasButtonClick: function onAliasButtonClick() {
      dispatch((0, _actions.showAliasEditor)());
      dispatch((0, _actions2.addAliasRow)());
    },
    onIdentifierButtonClick: function onIdentifierButtonClick() {
      dispatch((0, _actions.showIdentifierEditor)());
      dispatch((0, _actions3.addIdentifierRow)());
    }
  };
}
var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(ButtonBar);
exports.default = _default;
//# sourceMappingURL=button-bar.js.map