@grafosoft/excel-validator 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -85,7 +85,7 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
85
85
  const [currentPage, setCurrentPage] = (0, react_1.useState)(1);
86
86
  const [focusTarget, setFocusTarget] = (0, react_1.useState)(null);
87
87
  const [fetchCatalogsByUrl, setFetchCatalogsByUrl] = (0, react_1.useState)({});
88
- const [stringEmptyResultsByQuery, setStringEmptyResultsByQuery] = (0, react_1.useState)({});
88
+ const [stringEmptyCatalogsByUrl, setStringEmptyCatalogsByUrl] = (0, react_1.useState)({});
89
89
  (0, react_1.useEffect)(() => {
90
90
  let isCancelled = false;
91
91
  const fetchRules = resolvedJsonValidator.filter((item) => typeof item === "object" &&
@@ -136,13 +136,9 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
136
136
  .filter((row) => { var _a, _b; return ((_b = (_a = row[0]) === null || _a === void 0 ? void 0 : _a.toString().trim()) !== null && _b !== void 0 ? _b : "") !== ""; });
137
137
  const queryUrls = new Set();
138
138
  stringEmptyRules.forEach(({ item, index }) => {
139
- filteredRows.forEach((row) => {
140
- var _a;
141
- const cellValue = String((_a = row[index]) !== null && _a !== void 0 ? _a : "").trim();
142
- if (cellValue !== "") {
143
- queryUrls.add(`${item.url}&${encodeURIComponent(item.prop)}=${encodeURIComponent(cellValue)}`);
144
- }
145
- });
139
+ if (filteredRows.some((row) => { var _a; return String((_a = row[index]) !== null && _a !== void 0 ? _a : "").trim() !== ""; })) {
140
+ queryUrls.add(item.url);
141
+ }
146
142
  });
147
143
  if (queryUrls.size === 0) {
148
144
  return;
@@ -165,7 +161,7 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
165
161
  }
166
162
  }));
167
163
  if (!isCancelled) {
168
- setStringEmptyResultsByQuery((prev) => (Object.assign(Object.assign({}, prev), Object.fromEntries(entries))));
164
+ setStringEmptyCatalogsByUrl((prev) => (Object.assign(Object.assign({}, prev), Object.fromEntries(entries))));
169
165
  }
170
166
  };
171
167
  void loadStringEmptyResults();
@@ -394,12 +390,14 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
394
390
  return validationResult;
395
391
  }
396
392
  }
397
- const queryKey = `${rule.url}&${encodeURIComponent(rule.prop)}=${encodeURIComponent(trimmedValue)}`;
398
- const queryResult = stringEmptyResultsByQuery[queryKey];
399
- if (queryResult === undefined) {
393
+ const catalog = stringEmptyCatalogsByUrl[rule.url];
394
+ if (catalog === undefined) {
400
395
  return { valid: true, message: "" };
401
396
  }
402
- const alreadyExists = queryResult.length > 0;
397
+ const alreadyExists = catalog.some((catalogItem) => {
398
+ const propValue = catalogItem[rule.prop];
399
+ return String(propValue !== null && propValue !== void 0 ? propValue : "").trim() === trimmedValue;
400
+ });
403
401
  return {
404
402
  valid: !alreadyExists,
405
403
  message: alreadyExists
@@ -429,7 +427,7 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
429
427
  matrix,
430
428
  resolvedJsonValidator,
431
429
  fetchCatalogsByUrl,
432
- stringEmptyResultsByQuery,
430
+ stringEmptyCatalogsByUrl,
433
431
  ]);
434
432
  const hasBalanceDifference = (0, react_1.useMemo)(() => {
435
433
  var _a;
@@ -26,7 +26,7 @@ const ExcelValidator = ({ initData, fileContent, matrix, validationErrors, onSel
26
26
  const content = lines.join("\n");
27
27
  const base64 = btoa(String.fromCharCode(...new TextEncoder().encode(content)));
28
28
  try {
29
- const response = await fetch(`http://lab.globho.com/api/v1/plains/upload?companyId=&apikey=`, {
29
+ const response = await fetch(`${initData.environment}api/v1/plains/upload?companyId=${initData.companyId}&apikey=${initData.apikey}`, {
30
30
  method: "POST",
31
31
  headers: {
32
32
  "Content-Type": "application/json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafosoft/excel-validator",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "React component to validate Excel files against configurable JSON rules.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",