UNPKG

kea-react

Version:

Componentes comunes de react

59 lines (58 loc) 2.74 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var modal_1 = require("../../modal"); var mappingComp_1 = require("./mappingComp"); /**Intercambia 2 elementos de un arreglo, si los indices dados estan afuera del arreglo, devuelve el arreglo sin modificar */ function swapItems(array, a, b) { var inside = function (x) { return x >= 0 && x < array.length; }; if (!inside(a) || !inside(b)) return array; return array.map(function (x, i, arr) { return i == a ? arr[b] : i == b ? arr[a] : arr[i]; }); } /**Mueve un elemento del arreglo, si el elemento no se puede mover en esta dirección debido a que esta en la esquina del arreglo devuelve el arreglo sin modificar */ function moveItem(array, index, dir) { return swapItems(array, index, index + (dir == "up" ? -1 : +1)); } var MappingComponent = /** @class */ (function (_super) { __extends(MappingComponent, _super); function MappingComponent() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.handleOnMappingChange = function (mapping) { var oldValue = _this.props.state; var newwValue = __assign({}, oldValue, { mapping: mapping }); _this.props.onStateChange(newwValue); }; return _this; } MappingComponent.prototype.render = function () { var props = this.props; return (this.props.show ? React.createElement(modal_1.Modal, { buttonsWithKey: [], onClose: this.props.onClose, title: "Seleccionar columnas" }, React.createElement(mappingComp_1.ColumnMappingComponent, { columnas: props.columnas, onChange: this.handleOnMappingChange, value: props.state.mapping })) : null); }; return MappingComponent; }(React.PureComponent)); exports.MappingComponent = MappingComponent;