infinity-forge
Version:
123 lines • 13.3 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__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;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Table = Table;
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
var router_1 = require("next/router");
var ui_1 = require("../../../../../../ui/index.js");
var tr_1 = require("./tr/index.js");
var export_1 = require("./export/index.js");
var filters_1 = require("./filters/index.js");
var create_1 = require("./create/index.js");
var thead_item_1 = require("./thead-item/index.js");
var pagination_1 = require("./pagination/index.js");
var skeleton_table_1 = require("./skeleton-table/index.js");
var active_filters_1 = require("./active-filters/index.js");
var S = __importStar(require("./styles.js"));
function Table(props) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
var configs = props.configs, isFetching = props.isFetching, columnsConfiguration = props.columnsConfiguration, tableInformations = props.tableInformations;
var router = (0, router_1.useRouter)();
var _window = (0, ui_1.useWindow)();
var tableRef = (0, react_1.useRef)(null);
var loadingTable = configs.isLoading || isFetching;
var pagination = (configs === null || configs === void 0 ? void 0 : configs.pagination) || (tableInformations === null || tableInformations === void 0 ? void 0 : tableInformations.pagination);
var paramToSearch = ((_b = (((_a = router.query) === null || _a === void 0 ? void 0 : _a.search) || '')) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || '';
var tableItems = configs.tableData || (tableInformations === null || tableInformations === void 0 ? void 0 : tableInformations.items);
var tableFilered = (configs === null || configs === void 0 ? void 0 : configs.enableSearchInSelf)
? tableItems && tableItems.length > 0
? tableItems === null || tableItems === void 0 ? void 0 : tableItems.filter(function (item) {
var _a;
var stringfyItem = item ? JSON.stringify(item) : '';
return (_a = stringfyItem === null || stringfyItem === void 0 ? void 0 : stringfyItem.toLowerCase()) === null || _a === void 0 ? void 0 : _a.includes(paramToSearch);
})
: null
: null;
var tableData = tableFilered || tableItems || [];
if (!_window) {
return;
}
if (((_d = (_c = props === null || props === void 0 ? void 0 : props.configs) === null || _c === void 0 ? void 0 : _c.mobile) === null || _d === void 0 ? void 0 : _d.mediaQuery) && (_window === null || _window === void 0 ? void 0 : _window.innerWidth) <= ((_f = (_e = props === null || props === void 0 ? void 0 : props.configs) === null || _e === void 0 ? void 0 : _e.mobile) === null || _f === void 0 ? void 0 : _f.mediaQuery)) {
return ((0, jsx_runtime_1.jsx)("div", { className: 'mobile_table', children: !loadingTable &&
tableItems &&
Array.isArray(tableItems) &&
(tableItems === null || tableItems === void 0 ? void 0 : tableItems.length) !== 0 &&
(tableData === null || tableData === void 0 ? void 0 : tableData.map(function (data) {
return (0, jsx_runtime_1.jsx)(props.configs.mobile.Component, __assign({}, data), data.id);
})) }));
}
var exportsOfConfigs = configs.exports && ((_g = configs.exports) === null || _g === void 0 ? void 0 : _g.length) > 0 && (configs === null || configs === void 0 ? void 0 : configs.exports);
var exportsOfTableInformations = (tableInformations === null || tableInformations === void 0 ? void 0 : tableInformations.exports) && ((_h = tableInformations === null || tableInformations === void 0 ? void 0 : tableInformations.exports) === null || _h === void 0 ? void 0 : _h.length) > 0 && (tableInformations === null || tableInformations === void 0 ? void 0 : tableInformations.exports);
var hasExports = exportsOfConfigs ? exportsOfConfigs : exportsOfTableInformations;
var hasActions = columnsConfiguration === null || columnsConfiguration === void 0 ? void 0 : columnsConfiguration.actions;
var configsFilter = ((_j = props === null || props === void 0 ? void 0 : props.configs) === null || _j === void 0 ? void 0 : _j.customFilters) || [];
var apiFilters = ((_k = props === null || props === void 0 ? void 0 : props.tableInformations) === null || _k === void 0 ? void 0 : _k.filters) || [];
var filters = __spreadArray(__spreadArray([], apiFilters, true), configsFilter, true);
return ((0, jsx_runtime_1.jsx)(ui_1.Error, { name: 'table-component', children: (0, jsx_runtime_1.jsxs)("div", { className: 'table_infinity_forge', style: { width: "100%" }, children: [(((_l = props.configs) === null || _l === void 0 ? void 0 : _l.search) || filters.length > 0 || hasExports || hasActions) && ((0, jsx_runtime_1.jsxs)(S.TopActions, { className: 'top-actions', children: [(0, jsx_runtime_1.jsx)(filters_1.Filters, __assign({}, props)), (0, jsx_runtime_1.jsxs)("div", { className: 'right', children: [hasExports && (0, jsx_runtime_1.jsx)(export_1.Export, { exports: hasExports }), hasActions && (0, jsx_runtime_1.jsx)(create_1.CreateAction, { actions: columnsConfiguration === null || columnsConfiguration === void 0 ? void 0 : columnsConfiguration.actions })] })] })), (0, jsx_runtime_1.jsx)(active_filters_1.ActiveFilters, __assign({}, props)), (0, jsx_runtime_1.jsx)(S.Table, { className: 'table_container', children: (0, jsx_runtime_1.jsxs)("div", { ref: tableRef, children: [(0, jsx_runtime_1.jsxs)("table", { children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [columnsConfiguration.actions && (0, jsx_runtime_1.jsx)("th", { style: { width: '100px' } }), (_m = columnsConfiguration.columns) === null || _m === void 0 ? void 0 : _m.map(function (colunm, index) {
if (colunm.enabled === false) {
return (0, jsx_runtime_1.jsx)(react_1.Fragment, {}, colunm.id + index);
}
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("th", { style: { width: 20 } }), (0, jsx_runtime_1.jsx)(thead_item_1.THeadItem, { index: index, colunm: colunm, tableItems: tableItems, disableOrdenationTable: configs === null || configs === void 0 ? void 0 : configs.disableOrdenationTable }, colunm.id + index)] }));
})] }) }), (0, jsx_runtime_1.jsxs)("tbody", { children: [!loadingTable &&
tableItems &&
Array.isArray(tableItems) &&
(tableItems === null || tableItems === void 0 ? void 0 : tableItems.length) !== 0 &&
(tableData === null || tableData === void 0 ? void 0 : tableData.map(function (table, index) {
var _a;
return ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: (0, jsx_runtime_1.jsx)(tr_1.TR, { tableItems: tableItems, columnsConfiguration: columnsConfiguration, index: index, table: table, tableRef: tableRef, loadingTable: loadingTable }) }, (table === null || table === void 0 ? void 0 : table[(_a = props === null || props === void 0 ? void 0 : props.configs) === null || _a === void 0 ? void 0 : _a.tableKeyItem]) || table.id + String(index)));
})), loadingTable && ((0, jsx_runtime_1.jsxs)("tr", { style: { height: 0 }, children: [columnsConfiguration.columns.map(function (c, index) { return ((0, jsx_runtime_1.jsx)("td", { children: (0, jsx_runtime_1.jsx)("div", { style: { width: c.width + 'px' } }) }, index)); }), columnsConfiguration.actions && ((0, jsx_runtime_1.jsx)("td", { style: { width: '100%' }, children: (0, jsx_runtime_1.jsx)("div", { style: { width: '100%' } }) }))] }))] })] }), !loadingTable && (tableData === null || tableData === void 0 ? void 0 : tableData.length) === 0 && ((0, jsx_runtime_1.jsxs)("div", { className: 'error_table', children: [(0, jsx_runtime_1.jsxs)("svg", { xmlns: 'http://www.w3.org/2000/svg', width: '60', height: '60', viewBox: '0 0 60 60', fill: 'none', children: [(0, jsx_runtime_1.jsx)("path", { d: 'M49.8 18.3301H24.02C23.05 18.3301 22.26 19.1201 22.26 20.0901C22.26 21.0601 23.05 21.8501 24.02 21.8501H49.8C50.77 21.8501 51.56 21.0601 51.56 20.0901C51.56 19.1201 50.77 18.3301 49.8 18.3301Z', fill: '#828282' }), (0, jsx_runtime_1.jsx)("path", { d: 'M19.85 47.7001C20.19 48.0401 20.64 48.2101 21.09 48.2101C21.54 48.2101 21.99 48.0401 22.33 47.7001C23.02 47.0101 23.02 45.9001 22.33 45.2101L18.3 41.1801L22.33 37.1501C23.02 36.4601 23.02 35.3501 22.33 34.6601C21.64 33.9701 20.53 33.9701 19.84 34.6601L15.81 38.6901L11.78 34.6601C11.09 33.9701 9.97996 33.9701 9.28996 34.6601C8.59996 35.3501 8.59996 36.4601 9.28996 37.1501L13.32 41.1801L9.28996 45.2101C8.59996 45.9001 8.59996 47.0101 9.28996 47.7001C9.62996 48.0401 10.08 48.2101 10.53 48.2101C10.98 48.2101 11.43 48.0401 11.77 47.7001L15.8 43.6701L19.83 47.7001H19.85Z', fill: '#828282' }), (0, jsx_runtime_1.jsx)("path", { d: 'M59.75 9.29004C59.75 6.38004 57.39 4.01004 54.48 4.01004H19.34C16.43 4.00004 14.07 6.36004 14.07 9.27004V25.45C6.17001 26.33 0.0100098 33.04 0.0100098 41.17C0.0100098 49.89 7.11001 56.99 15.83 56.99H54.5C57.41 56.99 59.77 54.62 59.77 51.72V9.29004H59.75ZM15.82 53.48C9.04001 53.48 3.52001 47.96 3.52001 41.18C3.52001 34.4 9.04001 28.88 15.82 28.88C22.6 28.88 28.12 34.4 28.12 41.18C28.12 47.96 22.6 53.48 15.82 53.48ZM54.49 53.48H25.75C28.91 50.92 31.07 47.18 31.54 42.93H49.8C50.77 42.93 51.56 42.14 51.56 41.17C51.56 40.2 50.77 39.41 49.8 39.41H31.54C31.25 36.83 30.34 34.43 28.97 32.38H49.81C50.78 32.38 51.57 31.59 51.57 30.62C51.57 29.65 50.78 28.86 49.81 28.86H25.76C23.47 27.01 20.66 25.78 17.59 25.44V9.27004C17.59 8.30004 18.38 7.51004 19.35 7.51004H54.49C55.46 7.52004 56.25 8.31004 56.25 9.28004V51.72C56.26 52.69 55.48 53.48 54.51 53.48H54.49Z', fill: '#828282' })] }), (0, jsx_runtime_1.jsx)("h3", { children: configs === null || configs === void 0 ? void 0 : configs.errorMessage })] })), loadingTable && (0, jsx_runtime_1.jsx)(skeleton_table_1.SkeletonTable, {})] }) }), !(configs === null || configs === void 0 ? void 0 : configs.disablePagination) && pagination && ((0, jsx_runtime_1.jsxs)(S.TableBottom, { className: 'table-bottom', children: [pagination && ((0, jsx_runtime_1.jsxs)("span", { children: ["Mostrando", ' ', (0, jsx_runtime_1.jsx)("strong", { children: pagination.pageSize > pagination.totalItems ? pagination.totalItems : pagination === null || pagination === void 0 ? void 0 : pagination.pageSize }), ' ', "de ", (0, jsx_runtime_1.jsx)("strong", { children: pagination === null || pagination === void 0 ? void 0 : pagination.totalItems }), " resultados"] })), pagination && (0, jsx_runtime_1.jsx)(pagination_1.PaginationTable, __assign({}, pagination))] }))] }) }));
}
//# sourceMappingURL=index.js.map