UNPKG

@etsoo/materialui

Version:

TypeScript Material-UI Implementation

68 lines (67 loc) 3.48 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ShowDataComparison = void 0; exports.IsAuditLineUpdateData = IsAuditLineUpdateData; const jsx_runtime_1 = require("react/jsx-runtime"); const notificationbase_1 = require("@etsoo/notificationbase"); const shared_1 = require("@etsoo/shared"); const ReactApp_1 = require("./app/ReactApp"); const Table_1 = __importDefault(require("@mui/material/Table")); const TableHead_1 = __importDefault(require("@mui/material/TableHead")); const TableRow_1 = __importDefault(require("@mui/material/TableRow")); const TableCell_1 = __importDefault(require("@mui/material/TableCell")); const TableBody_1 = __importDefault(require("@mui/material/TableBody")); /** * Check obj is instance of AuditLineChangesDto * @param obj Input * @returns Result */ function IsAuditLineUpdateData(obj) { return (typeof obj === "object" && "oldData" in obj && typeof obj.oldData === "object" && "newData" in obj && typeof obj.newData === "object"); } // Format value const formatValue = (value, app) => { if (value == null) return ""; if (value instanceof Date) return app.formatDate(value, "ds"); return `${value}`; }; /** * Show data comparison * @param data Data * @param modelTitle Model window title * @param getLabel Get label callback * @param equalCheck Equal check for properties */ const ShowDataComparison = (data, modelTitle, getLabel, equalCheck = true) => { // Global app const app = (0, ReactApp_1.useRequiredAppContext)(); // Labels const { dataComparison, field, newValue, oldValue } = app.getLabels("dataComparison", "field", "newValue", "oldValue"); modelTitle ??= dataComparison; getLabel ??= (key) => { return app.get(shared_1.Utils.formatInitial(key)) ?? key; }; const keys = new Set([ ...Object.keys(data.oldData), ...Object.keys(data.newData) ]); let rows = Array.from(keys).map((field) => ({ field, oldValue: data.oldData[field], newValue: data.newData[field] })); if (equalCheck) rows = rows.filter((item) => !shared_1.Utils.equals(item.oldValue, item.newValue)); const inputs = ((0, jsx_runtime_1.jsxs)(Table_1.default, { children: [(0, jsx_runtime_1.jsx)(TableHead_1.default, { children: (0, jsx_runtime_1.jsxs)(TableRow_1.default, { children: [(0, jsx_runtime_1.jsx)(TableCell_1.default, { width: "18%", children: field }), (0, jsx_runtime_1.jsx)(TableCell_1.default, { width: "41%", align: "right", children: oldValue }), (0, jsx_runtime_1.jsx)(TableCell_1.default, { width: "41%", align: "right", children: newValue })] }) }), (0, jsx_runtime_1.jsx)(TableBody_1.default, { children: rows.map((row) => ((0, jsx_runtime_1.jsxs)(TableRow_1.default, { children: [(0, jsx_runtime_1.jsx)(TableCell_1.default, { children: getLabel(row.field) }), (0, jsx_runtime_1.jsx)(TableCell_1.default, { align: "right", children: formatValue(row.oldValue, app) }), (0, jsx_runtime_1.jsx)(TableCell_1.default, { align: "right", children: formatValue(row.newValue, app) })] }, row.field))) })] })); app.notifier.alert([undefined, modelTitle], undefined, notificationbase_1.NotificationMessageType.Info, { fullScreen: app.smDown, inputs }); }; exports.ShowDataComparison = ShowDataComparison;