client/entity-editor/identifier-editor/actions.js

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.UPDATE_IDENTIFIER_VALUE = exports.UPDATE_IDENTIFIER_TYPE = exports.REMOVE_IDENTIFIER_ROW = exports.REMOVE_EMPTY_IDENTIFIERS = exports.HIDE_IDENTIFIER_EDITOR = exports.ADD_OTHER_ISBN = exports.ADD_IDENTIFIER_ROW = void 0;
exports.addIdentifierRow = addIdentifierRow;
exports.addOtherISBN = addOtherISBN;
exports.debouncedUpdateIdentifierValue = debouncedUpdateIdentifierValue;
exports.hideIdentifierEditor = hideIdentifierEditor;
exports.removeEmptyIdentifiers = removeEmptyIdentifiers;
exports.removeIdentifierRow = removeIdentifierRow;
exports.updateIdentifierType = updateIdentifierType;
/*
 * 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.
 */

var ADD_IDENTIFIER_ROW = 'ADD_IDENTIFIER_ROW';
exports.ADD_IDENTIFIER_ROW = ADD_IDENTIFIER_ROW;
var REMOVE_IDENTIFIER_ROW = 'REMOVE_IDENTIFIER_ROW';
exports.REMOVE_IDENTIFIER_ROW = REMOVE_IDENTIFIER_ROW;
var UPDATE_IDENTIFIER_TYPE = 'UPDATE_IDENTIFIER_TYPE';
exports.UPDATE_IDENTIFIER_TYPE = UPDATE_IDENTIFIER_TYPE;
var UPDATE_IDENTIFIER_VALUE = 'UPDATE_IDENTIFIER_VALUE';
exports.UPDATE_IDENTIFIER_VALUE = UPDATE_IDENTIFIER_VALUE;
var HIDE_IDENTIFIER_EDITOR = 'HIDE_IDENTIFIER_EDITOR';
exports.HIDE_IDENTIFIER_EDITOR = HIDE_IDENTIFIER_EDITOR;
var REMOVE_EMPTY_IDENTIFIERS = 'REMOVE_EMPTY_IDENTIFIERS';
exports.REMOVE_EMPTY_IDENTIFIERS = REMOVE_EMPTY_IDENTIFIERS;
var ADD_OTHER_ISBN = 'ADD_OTHER_ISBN';
exports.ADD_OTHER_ISBN = ADD_OTHER_ISBN;
/**
 * Produces an action indicating that the identifier editor should be hidden
 * from view.
 *
 * @see showIdentifierEditor
 *
 * @returns {Action} The resulting HIDE_IDENTIFIER_EDITOR action.
 */
function hideIdentifierEditor() {
  return {
    type: HIDE_IDENTIFIER_EDITOR
  };
}
var nextIdentifierRowId = 0;

/**
 * Produces an action indicating that a row for a new identifier should be added
 * to the identifier editor. The row is assigned an ID based on an incrementing
 * variable existing on the client.
 *
 * @returns {Action} The resulting ADD_IDENTIFIER_ROW action.
 */
function addIdentifierRow() {
  /*
   * Prepend 'n' here to indicate new identifier, and avoid conflicts with IDs
   * of existing identifiers.
   */
  return {
    payload: "n".concat(nextIdentifierRowId++),
    type: ADD_IDENTIFIER_ROW
  };
}

/**
 * Produces an action indicating that the row with the provided ID should be
 * removed from the identifier editor.
 *
 * @param {number} rowId - The ID for the row to be deleted.
 * @returns {Action} The resulting REMOVE_IDENTIFIER_ROW action.
 */
function removeIdentifierRow(rowId) {
  return {
    payload: rowId,
    type: REMOVE_IDENTIFIER_ROW
  };
}

/**
 * Produces an action indicating that the value for a particular identifier
 * within the editor should be updated with the provided value. Also
 * provides a suggestion for the identifier type based on the provided value,
 * if this is possible and it has not already been set. The action is marked to
 * be debounced by the keystroke debouncer defined for redux-debounce.
 *
 * @param {number} rowId - The ID of the row in the identifier editor to update.
 * @param {string} value - The new value to be used for the identifier value.
 * @param {number} suggestedType - The ID for the type suggested by the new
 *        value.
 * @param {boolean} doDebounce - flag for debouncing
 * @returns {Action} The resulting UPDATE_IDENTIFIER_VALUE action.
 */
function debouncedUpdateIdentifierValue(rowId, value, suggestedType) {
  var doDebounce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
  return {
    meta: {
      debounce: doDebounce ? 'keystroke' : null
    },
    payload: {
      rowId: rowId,
      suggestedType: suggestedType,
      value: value
    },
    type: UPDATE_IDENTIFIER_VALUE
  };
}

/**
 * Produces an action indicating that the type for a particular identifier
 * within the editor should be updated with the provided value.
 *
 * @param {number} rowId - The ID of the row in the identifier editor to update.
 * @param {number} value - The new value to be used for the identifier type ID.
 * @returns {Action} The resulting UPDATE_IDENTIFIER_TYPE action.
 */
function updateIdentifierType(rowId, value) {
  return {
    payload: {
      rowId: rowId,
      value: value
    },
    type: UPDATE_IDENTIFIER_TYPE
  };
}

/**
 * Produces an action indicating that the empty rows should be deleted.
 *
 * @returns {Action} The resulting REMOVE_EMPTY_IDENTIFIERS action.
 */
function removeEmptyIdentifiers() {
  return {
    type: REMOVE_EMPTY_IDENTIFIERS
  };
}

/**
 * Produces an action indicating that the new ISBN should be added to the Identifiers.
 *
 * @param {number} type - The type Id correspond to this ISBN.
 * @param {string} value - The value of this ISBN.
 * @returns {Action} The resulting ADD_OTHER_ISBN action.
 */

function addOtherISBN(type, value) {
  return {
    payload: {
      rowId: "n".concat(nextIdentifierRowId++),
      type: type,
      value: value
    },
    type: ADD_OTHER_ISBN
  };
}
//# sourceMappingURL=actions.js.map