UNPKG

infinity-forge

Version:
133 lines • 10.4 kB
"use strict"; 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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Actions = Actions; var jsx_runtime_1 = require("react/jsx-runtime"); var react_1 = require("react"); var link_1 = __importDefault(require("next/link")); var system_1 = require("../../../../../../../system/index.js"); var ui_1 = require("../../../../../../../ui/index.js"); var delete_1 = require("./delete/index.js"); var S = __importStar(require("./styles.js")); function Actions(_a) { var _this = this; var _b, _c, _d, _e, _f, _g, _h; var actions = _a.actions, table = _a.table, childrenItems = _a.childrenItems, handleToggle = _a.handleToggle, childrenConfigurations = _a.childrenConfigurations, oneItemTableHasChildrenKey = _a.oneItemTableHasChildrenKey; var _j = (0, react_1.useState)(false), open = _j[0], setOpen = _j[1]; var payload = __assign(__assign({}, ((actions === null || actions === void 0 ? void 0 : actions.edit) || {})), { tableItem: table }); var roleUser = (0, system_1.useAuthAdmin)().roleUser; var Configurations = (0, system_1.useInfraInjection)().Configurations; var editPermission = (0, system_1.usePermission)((_b = actions === null || actions === void 0 ? void 0 : actions.tablePermissions) === null || _b === void 0 ? void 0 : _b.edit); var enableToUpdate = ((_c = actions === null || actions === void 0 ? void 0 : actions.tablePermissions) === null || _c === void 0 ? void 0 : _c.edit) ? editPermission === null || editPermission === void 0 ? void 0 : editPermission.hasAccess : !((_e = (_d = Configurations === null || Configurations === void 0 ? void 0 : Configurations.table) === null || _d === void 0 ? void 0 : _d.accessControl) === null || _e === void 0 ? void 0 : _e.update) ? true : Configurations.table.accessControl.update.includes(roleUser); var editEnabled = (0, react_1.useMemo)(function () { if (!(actions === null || actions === void 0 ? void 0 : actions.edit)) return false; if (!enableToUpdate) return false; var enabledFn = actions.edit.enabled; if (typeof enabledFn === 'function') return !!enabledFn(table); return true; }, [actions === null || actions === void 0 ? void 0 : actions.edit, (_f = actions === null || actions === void 0 ? void 0 : actions.edit) === null || _f === void 0 ? void 0 : _f.enabled, enableToUpdate, table]); var modalEditProps = ((_g = actions === null || actions === void 0 ? void 0 : actions.edit) === null || _g === void 0 ? void 0 : _g.modal) || {}; return ((0, jsx_runtime_1.jsx)(S.Actions, { children: (0, jsx_runtime_1.jsxs)("div", { children: [oneItemTableHasChildrenKey && childrenConfigurations && ((0, jsx_runtime_1.jsx)("button", { onClick: childrenItems ? handleToggle : null, className: 'expand-btn', type: 'button', children: childrenItems && (0, jsx_runtime_1.jsx)(ui_1.Icon, { name: open ? 'IconTopChevron' : 'IconBottomChevron' }) })), editEnabled && (((_h = actions === null || actions === void 0 ? void 0 : actions.edit) === null || _h === void 0 ? void 0 : _h.link) ? ((0, jsx_runtime_1.jsx)(ui_1.Tooltip, { idTooltip: 'Actions', bgColor: '#fff', enableHover: true, content: 'Editar', trigger: (0, jsx_runtime_1.jsx)(link_1.default, { className: 'action-button', href: actions.edit.link.href(table), children: (0, jsx_runtime_1.jsx)(ui_1.Icon, { name: 'IconEdit' }) }) })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(ui_1.Modal, __assign({ open: open, onClose: function () { return setOpen(false); }, styles: __assign({ width: '100vw', maxWidth: '512px', borderRadius: 5 }, ((actions === null || actions === void 0 ? void 0 : actions.modalStyles) || {})) }, modalEditProps, { children: (0, jsx_runtime_1.jsx)(ui_1.DynamicFormHandler, __assign({}, payload, { formHandlerContextProps: { setOpen: setOpen }, onSucess: function (data) { return __awaiter(_this, void 0, void 0, function () { var response; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, actions.edit.onSucess(data, undefined, table)]; case 1: response = _a.sent(); return [2 /*return*/, response]; } }); }); }, onFinish: function () { setOpen(false); } })) })), (0, jsx_runtime_1.jsx)("span", { className: 'action-button', onClick: function () { return setOpen(true); }, children: (0, jsx_runtime_1.jsx)(ui_1.Tooltip, { idTooltip: '', bgColor: '#fff', enableHover: true, content: 'Editar', trigger: (0, jsx_runtime_1.jsx)("button", { type: 'button', children: (0, jsx_runtime_1.jsx)(ui_1.Icon, { name: 'IconEdit' }) }) }) })] }))), (actions === null || actions === void 0 ? void 0 : actions.detail) && ((0, jsx_runtime_1.jsx)(ui_1.Tooltip, { idTooltip: 'Actions', bgColor: '#fff', enableHover: true, content: 'Detalhe', trigger: (0, jsx_runtime_1.jsx)(link_1.default, { className: 'action-button', href: actions.detail(table), children: (0, jsx_runtime_1.jsx)(ui_1.Icon, { name: 'IconEye' }) }) })), (actions === null || actions === void 0 ? void 0 : actions.delete) && (0, jsx_runtime_1.jsx)(delete_1.ActionDelete, { actions: actions, table: table }), (actions === null || actions === void 0 ? void 0 : actions.custom) && actions.custom.length > 0 && actions.custom.map(function (Component, index) { return ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(Component, __assign({}, table)) }, 'custom' + index + Component.name)); })] }) })); } //# sourceMappingURL=index.js.map