strapi-plugin-bulk-updater 1.5.14 → 1.5.16
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.
- package/dist/_chunks/{BulkUpdater-B3m2_z--.mjs → BulkUpdater-Bj-8DvpD.mjs} +644 -166
- package/dist/_chunks/BulkUpdater-Bj-8DvpD.mjs.map +1 -0
- package/dist/_chunks/{BulkUpdater-Cn17jk6f.js → BulkUpdater-C7-KHLWq.js} +642 -164
- package/dist/_chunks/BulkUpdater-C7-KHLWq.js.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +539 -269
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +539 -269
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/_chunks/BulkUpdater-B3m2_z--.mjs.map +0 -1
- package/dist/_chunks/BulkUpdater-Cn17jk6f.js.map +0 -1
|
@@ -76,10 +76,11 @@ function parseCsvRows(csvText) {
|
|
|
76
76
|
}
|
|
77
77
|
return rows;
|
|
78
78
|
}
|
|
79
|
-
function
|
|
79
|
+
function parseCsvWithHeaders(csvText) {
|
|
80
80
|
const rows = parseCsvRows(csvText);
|
|
81
|
-
if (rows.length
|
|
81
|
+
if (rows.length === 0) return { headers: [], records: [] };
|
|
82
82
|
const headers = rows[0].map((h) => h.trim());
|
|
83
|
+
if (rows.length < 2) return { headers, records: [] };
|
|
83
84
|
const records = [];
|
|
84
85
|
for (let i = 1; i < rows.length; i++) {
|
|
85
86
|
const row = rows[i];
|
|
@@ -93,7 +94,125 @@ function parseCsv(csvText) {
|
|
|
93
94
|
});
|
|
94
95
|
records.push(record);
|
|
95
96
|
}
|
|
96
|
-
return records;
|
|
97
|
+
return { headers, records };
|
|
98
|
+
}
|
|
99
|
+
function escapeCsvCell(val) {
|
|
100
|
+
if (val === null || val === void 0) return "";
|
|
101
|
+
let str = "";
|
|
102
|
+
if (val instanceof Date) {
|
|
103
|
+
str = val.toISOString();
|
|
104
|
+
} else if (typeof val === "object") {
|
|
105
|
+
str = JSON.stringify(val);
|
|
106
|
+
} else {
|
|
107
|
+
str = String(val);
|
|
108
|
+
}
|
|
109
|
+
str = str.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
110
|
+
if (/^[=+@-]/.test(str)) {
|
|
111
|
+
str = `'${str}`;
|
|
112
|
+
}
|
|
113
|
+
if (str.includes(",") || str.includes('"') || str.includes("\n") || str.includes("\r")) {
|
|
114
|
+
return `"${str.replace(/"/g, '""')}"`;
|
|
115
|
+
}
|
|
116
|
+
return str;
|
|
117
|
+
}
|
|
118
|
+
function sanitizeUserErrorMessage(msg) {
|
|
119
|
+
if (msg === null || msg === void 0) return "Error processing row";
|
|
120
|
+
const raw = typeof msg === "string" ? msg : String(msg);
|
|
121
|
+
const cleanedLines = raw.split(/\r?\n/).filter((line) => !/^\s+at\s+.+(\(.+\)|:\d+:\d+)\s*$/.test(line)).map((line) => line.trim()).filter(Boolean);
|
|
122
|
+
return cleanedLines.join(" ").trim() || "Error processing row";
|
|
123
|
+
}
|
|
124
|
+
function resolveErrorColumnName(existingHeaders) {
|
|
125
|
+
const existingLower = new Set(
|
|
126
|
+
existingHeaders.map((h) => String(h || "").trim().toLowerCase())
|
|
127
|
+
);
|
|
128
|
+
if (!existingLower.has("error")) return "Error";
|
|
129
|
+
if (!existingLower.has("import error")) return "Import Error";
|
|
130
|
+
let suffix = 2;
|
|
131
|
+
while (existingLower.has(`import error (${suffix})`)) {
|
|
132
|
+
suffix++;
|
|
133
|
+
}
|
|
134
|
+
return `Import Error (${suffix})`;
|
|
135
|
+
}
|
|
136
|
+
function formatErrorCsvFilename(collectionTypeOrUid, date = /* @__PURE__ */ new Date()) {
|
|
137
|
+
const rawSegment = collectionTypeOrUid ? String(collectionTypeOrUid).split(".").pop() || String(collectionTypeOrUid) : "collection";
|
|
138
|
+
const safeType = rawSegment.replace(/[^a-zA-Z0-9_-]+/g, "_").replace(/^_+|_+$/g, "") || "collection";
|
|
139
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
140
|
+
const stamp = `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}_${pad(
|
|
141
|
+
date.getHours()
|
|
142
|
+
)}${pad(date.getMinutes())}${pad(date.getSeconds())}`;
|
|
143
|
+
return `error_${safeType}_${stamp}.csv`;
|
|
144
|
+
}
|
|
145
|
+
function buildErrorCsv(options) {
|
|
146
|
+
const { headers, failedRows } = options || {};
|
|
147
|
+
if (!Array.isArray(failedRows) || failedRows.length === 0) {
|
|
148
|
+
return {
|
|
149
|
+
csvContent: "",
|
|
150
|
+
headers: headers ? [...headers] : [],
|
|
151
|
+
errorColumnName: "Error",
|
|
152
|
+
errorCount: 0
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const groupedByRow = /* @__PURE__ */ new Map();
|
|
156
|
+
for (const item of failedRows) {
|
|
157
|
+
if (!item || typeof item !== "object") continue;
|
|
158
|
+
const rowNum = typeof item.row === "number" && !isNaN(item.row) ? item.row : groupedByRow.size + 2;
|
|
159
|
+
const msg = sanitizeUserErrorMessage(item.error);
|
|
160
|
+
const existing = groupedByRow.get(rowNum);
|
|
161
|
+
if (existing) {
|
|
162
|
+
if (!existing.messages.includes(msg)) {
|
|
163
|
+
existing.messages.push(msg);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
groupedByRow.set(rowNum, {
|
|
167
|
+
row: rowNum,
|
|
168
|
+
documentId: item.documentId,
|
|
169
|
+
messages: [msg],
|
|
170
|
+
originalRow: item.originalRow && typeof item.originalRow === "object" ? item.originalRow : {}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const orderedEntries = Array.from(groupedByRow.values()).sort((a, b) => a.row - b.row);
|
|
175
|
+
if (orderedEntries.length === 0) {
|
|
176
|
+
return {
|
|
177
|
+
csvContent: "",
|
|
178
|
+
headers: headers ? [...headers] : [],
|
|
179
|
+
errorColumnName: "Error",
|
|
180
|
+
errorCount: 0
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
let baseHeaders = [];
|
|
184
|
+
if (Array.isArray(headers) && headers.length > 0) {
|
|
185
|
+
baseHeaders = [...headers];
|
|
186
|
+
} else {
|
|
187
|
+
const keySet = /* @__PURE__ */ new Set();
|
|
188
|
+
for (const entry of orderedEntries) {
|
|
189
|
+
for (const k of Object.keys(entry.originalRow || {})) {
|
|
190
|
+
if (!keySet.has(k)) {
|
|
191
|
+
keySet.add(k);
|
|
192
|
+
baseHeaders.push(k);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const errorColumnName = resolveErrorColumnName(baseHeaders);
|
|
198
|
+
const finalHeaders = [...baseHeaders, errorColumnName];
|
|
199
|
+
const lines = [];
|
|
200
|
+
lines.push(finalHeaders.map(escapeCsvCell).join(","));
|
|
201
|
+
for (const entry of orderedEntries) {
|
|
202
|
+
const cells = baseHeaders.map((h) => {
|
|
203
|
+
const val = entry.originalRow ? entry.originalRow[h] : "";
|
|
204
|
+
return escapeCsvCell(val === void 0 || val === null ? "" : val);
|
|
205
|
+
});
|
|
206
|
+
cells.push(escapeCsvCell(entry.messages.join("; ")));
|
|
207
|
+
lines.push(cells.join(","));
|
|
208
|
+
}
|
|
209
|
+
const csvContent = "\uFEFF" + lines.join("\r\n") + "\r\n";
|
|
210
|
+
return {
|
|
211
|
+
csvContent,
|
|
212
|
+
headers: finalHeaders,
|
|
213
|
+
errorColumnName,
|
|
214
|
+
errorCount: orderedEntries.length
|
|
215
|
+
};
|
|
97
216
|
}
|
|
98
217
|
const LIFECYCLE_STATUS_WORDS = /* @__PURE__ */ new Set([
|
|
99
218
|
"pending review",
|
|
@@ -238,11 +357,23 @@ function getEntryLifecycleStatus(entry, col, pendingBatches = []) {
|
|
|
238
357
|
function CsvManagerTab() {
|
|
239
358
|
const { get, post } = admin.useFetchClient();
|
|
240
359
|
const { toggleNotification } = admin.useNotification();
|
|
360
|
+
const fileInputRef = React.useRef(null);
|
|
361
|
+
const countAbortControllerRef = React.useRef(null);
|
|
241
362
|
const [collections, setCollections] = React.useState([]);
|
|
242
363
|
const [loadingCollections, setLoadingCollections] = React.useState(true);
|
|
243
364
|
const [selectedUid, setSelectedUid] = React.useState("");
|
|
244
365
|
const [collectionEntries, setCollectionEntries] = React.useState([]);
|
|
245
366
|
const [pendingBatches, setPendingBatches] = React.useState([]);
|
|
367
|
+
const [relationsMeta, setRelationsMeta] = React.useState({});
|
|
368
|
+
const [attributesMeta, setAttributesMeta] = React.useState({});
|
|
369
|
+
const [searchAttribute, setSearchAttribute] = React.useState("");
|
|
370
|
+
const [filterOperator, setFilterOperator] = React.useState("none");
|
|
371
|
+
const [filterQuery, setFilterQuery] = React.useState("");
|
|
372
|
+
const [entrySearch, setEntrySearch] = React.useState("");
|
|
373
|
+
const [matchingCount, setMatchingCount] = React.useState(null);
|
|
374
|
+
const [countLoading, setCountLoading] = React.useState(false);
|
|
375
|
+
const [searchRelationOptions, setSearchRelationOptions] = React.useState([]);
|
|
376
|
+
const [searchRelationOptionsLoading, setSearchRelationOptionsLoading] = React.useState(false);
|
|
246
377
|
const [exportLimit, setExportLimit] = React.useState(0);
|
|
247
378
|
const [exportLimitInput, setExportLimitInput] = React.useState("");
|
|
248
379
|
const [exportingCollection, setExportingCollection] = React.useState(false);
|
|
@@ -253,7 +384,7 @@ function CsvManagerTab() {
|
|
|
253
384
|
const [selectedRuleId, setSelectedRuleId] = React.useState("");
|
|
254
385
|
const [importMode, setImportMode] = React.useState("auto");
|
|
255
386
|
const [publishOnImport, setPublishOnImport] = React.useState(true);
|
|
256
|
-
const [
|
|
387
|
+
const [originalHeaders, setOriginalHeaders] = React.useState([]);
|
|
257
388
|
const [fileName, setFileName] = React.useState("");
|
|
258
389
|
const [allParsedRecords, setAllParsedRecords] = React.useState([]);
|
|
259
390
|
const [previewPage, setPreviewPage] = React.useState(1);
|
|
@@ -261,6 +392,8 @@ function CsvManagerTab() {
|
|
|
261
392
|
const [importing, setImporting] = React.useState(false);
|
|
262
393
|
const [importProgress, setImportProgress] = React.useState(null);
|
|
263
394
|
const [importResult, setImportResult] = React.useState(null);
|
|
395
|
+
const [errorReport, setErrorReport] = React.useState(null);
|
|
396
|
+
const activeBatchIdRef = React.useRef(null);
|
|
264
397
|
const [executionWindow, setExecutionWindow] = React.useState(null);
|
|
265
398
|
const [preflightLoading, setPreflightLoading] = React.useState(false);
|
|
266
399
|
const [preflightReport, setPreflightReport] = React.useState(null);
|
|
@@ -290,10 +423,12 @@ function CsvManagerTab() {
|
|
|
290
423
|
if (modelsRes.data?.collections) {
|
|
291
424
|
loadedCollections = modelsRes.data.collections;
|
|
292
425
|
setCollections(loadedCollections);
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
426
|
+
}
|
|
427
|
+
if (modelsRes.data?.relationsMeta) {
|
|
428
|
+
setRelationsMeta(modelsRes.data.relationsMeta);
|
|
429
|
+
}
|
|
430
|
+
if (modelsRes.data?.attributesMeta) {
|
|
431
|
+
setAttributesMeta(modelsRes.data.attributesMeta);
|
|
297
432
|
}
|
|
298
433
|
if (rulesRes.data?.rules) {
|
|
299
434
|
setRules(rulesRes.data.rules);
|
|
@@ -311,6 +446,98 @@ function CsvManagerTab() {
|
|
|
311
446
|
setLoadingCollections(false);
|
|
312
447
|
}
|
|
313
448
|
};
|
|
449
|
+
const getAttrDepth = (attr) => attributesMeta[attr]?.depth ?? (attr.includes(".") ? attr.split(".").length - 1 : 0);
|
|
450
|
+
React.useEffect(() => {
|
|
451
|
+
if (searchAttribute && relationsMeta[searchAttribute]) {
|
|
452
|
+
fetchSearchRelationOptions(relationsMeta[searchAttribute].targetUid);
|
|
453
|
+
} else {
|
|
454
|
+
setSearchRelationOptions([]);
|
|
455
|
+
}
|
|
456
|
+
}, [searchAttribute, relationsMeta]);
|
|
457
|
+
const fetchSearchRelationOptions = async (targetUid) => {
|
|
458
|
+
try {
|
|
459
|
+
setSearchRelationOptionsLoading(true);
|
|
460
|
+
const res = await get(`/bulk-updater/relation-options?targetUid=${encodeURIComponent(targetUid)}`);
|
|
461
|
+
if (res.data && res.data.success) {
|
|
462
|
+
setSearchRelationOptions(res.data.options || []);
|
|
463
|
+
}
|
|
464
|
+
} catch {
|
|
465
|
+
setSearchRelationOptions([]);
|
|
466
|
+
} finally {
|
|
467
|
+
setSearchRelationOptionsLoading(false);
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
const handleCollectionChange = (newUid) => {
|
|
471
|
+
if (newUid === selectedUid) return;
|
|
472
|
+
if (countAbortControllerRef.current) {
|
|
473
|
+
countAbortControllerRef.current.abort();
|
|
474
|
+
}
|
|
475
|
+
activeBatchIdRef.current = null;
|
|
476
|
+
setSelectedUid(newUid);
|
|
477
|
+
setAllParsedRecords([]);
|
|
478
|
+
setOriginalHeaders([]);
|
|
479
|
+
setFileName("");
|
|
480
|
+
setPreviewPage(1);
|
|
481
|
+
setImportProgress(null);
|
|
482
|
+
setImportResult(null);
|
|
483
|
+
setErrorReport(null);
|
|
484
|
+
setPreflightReport(null);
|
|
485
|
+
setPreflightLoading(false);
|
|
486
|
+
setImporting(false);
|
|
487
|
+
if (fileInputRef.current) {
|
|
488
|
+
fileInputRef.current.value = "";
|
|
489
|
+
}
|
|
490
|
+
setSearchAttribute("");
|
|
491
|
+
setFilterOperator("none");
|
|
492
|
+
setFilterQuery("");
|
|
493
|
+
setEntrySearch("");
|
|
494
|
+
setMatchingCount(null);
|
|
495
|
+
setCountLoading(Boolean(newUid));
|
|
496
|
+
};
|
|
497
|
+
React.useEffect(() => {
|
|
498
|
+
if (!selectedUid) {
|
|
499
|
+
setMatchingCount(null);
|
|
500
|
+
setCountLoading(false);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
setCountLoading(true);
|
|
504
|
+
const timer = setTimeout(async () => {
|
|
505
|
+
if (countAbortControllerRef.current) {
|
|
506
|
+
countAbortControllerRef.current.abort();
|
|
507
|
+
}
|
|
508
|
+
const controller = new AbortController();
|
|
509
|
+
countAbortControllerRef.current = controller;
|
|
510
|
+
try {
|
|
511
|
+
const params = new URLSearchParams({
|
|
512
|
+
page: "1",
|
|
513
|
+
pageSize: "1"
|
|
514
|
+
});
|
|
515
|
+
if (searchAttribute) {
|
|
516
|
+
params.set("attribute", searchAttribute);
|
|
517
|
+
params.set("searchAttribute", searchAttribute);
|
|
518
|
+
}
|
|
519
|
+
if (filterOperator && filterOperator !== "none") {
|
|
520
|
+
params.set("filterOperator", filterOperator);
|
|
521
|
+
if (filterQuery) params.set("filterQuery", filterQuery);
|
|
522
|
+
}
|
|
523
|
+
if (entrySearch && entrySearch.trim()) {
|
|
524
|
+
params.set("search", entrySearch.trim());
|
|
525
|
+
}
|
|
526
|
+
const res = await get(`/bulk-updater/collections/${selectedUid}/entries?${params.toString()}`, {
|
|
527
|
+
signal: controller.signal
|
|
528
|
+
});
|
|
529
|
+
if (res.data) {
|
|
530
|
+
const total = res.data.pagination?.total ?? (Array.isArray(res.data.entries) ? res.data.entries.length : 0);
|
|
531
|
+
setMatchingCount(total);
|
|
532
|
+
}
|
|
533
|
+
} catch (err) {
|
|
534
|
+
if (!ValidationRulesTab.isAbortError(err)) ;
|
|
535
|
+
} finally {
|
|
536
|
+
setCountLoading(false);
|
|
537
|
+
}
|
|
538
|
+
}, 300);
|
|
539
|
+
return () => clearTimeout(timer);
|
|
540
|
+
}, [selectedUid, searchAttribute, filterOperator, filterQuery, entrySearch]);
|
|
314
541
|
const fetchAndEnrichEntries = async (colUid, cols = collections, batches = pendingBatches) => {
|
|
315
542
|
if (!colUid) return [];
|
|
316
543
|
try {
|
|
@@ -393,7 +620,17 @@ function CsvManagerTab() {
|
|
|
393
620
|
if (!selectedUid || exportingCollection) return;
|
|
394
621
|
try {
|
|
395
622
|
setExportingCollection(true);
|
|
396
|
-
const
|
|
623
|
+
const queryParams = new URLSearchParams();
|
|
624
|
+
if (exportLimit > 0) queryParams.set("limit", String(exportLimit));
|
|
625
|
+
if (searchAttribute) queryParams.set("searchAttribute", searchAttribute);
|
|
626
|
+
if (filterOperator && filterOperator !== "none") {
|
|
627
|
+
queryParams.set("filterOperator", filterOperator);
|
|
628
|
+
if (filterQuery) queryParams.set("filterQuery", filterQuery);
|
|
629
|
+
}
|
|
630
|
+
if (entrySearch && entrySearch.trim()) {
|
|
631
|
+
queryParams.set("search", entrySearch.trim());
|
|
632
|
+
}
|
|
633
|
+
const res = await get(`/bulk-updater/csv/export/${selectedUid}?${queryParams.toString()}`);
|
|
397
634
|
const csvStr = res.data?.csvContent || (typeof res.data === "string" ? res.data : "");
|
|
398
635
|
const filename = res.data?.filename || `${selectedUid.split(".").pop()}_export.csv`;
|
|
399
636
|
downloadCsvFile(csvStr, filename);
|
|
@@ -455,43 +692,76 @@ function CsvManagerTab() {
|
|
|
455
692
|
const handleFileUpload = (e) => {
|
|
456
693
|
const file = e.target.files?.[0];
|
|
457
694
|
if (!file) return;
|
|
695
|
+
activeBatchIdRef.current = null;
|
|
458
696
|
setFileName(file.name);
|
|
459
697
|
setImportResult(null);
|
|
460
698
|
setImportProgress(null);
|
|
699
|
+
setPreflightReport(null);
|
|
700
|
+
setErrorReport(null);
|
|
701
|
+
setOriginalHeaders([]);
|
|
461
702
|
const reader = new FileReader();
|
|
462
703
|
reader.onload = (event) => {
|
|
463
704
|
const text = event.target?.result;
|
|
464
|
-
setCsvRawText(text);
|
|
465
705
|
try {
|
|
466
|
-
const records =
|
|
467
|
-
|
|
468
|
-
setAllParsedRecords(
|
|
706
|
+
const { headers, records } = parseCsvWithHeaders(text);
|
|
707
|
+
setOriginalHeaders(headers);
|
|
708
|
+
setAllParsedRecords(records);
|
|
469
709
|
setPreviewPage(1);
|
|
470
710
|
} catch (err) {
|
|
711
|
+
setOriginalHeaders([]);
|
|
471
712
|
setAllParsedRecords([]);
|
|
472
713
|
}
|
|
473
714
|
};
|
|
474
715
|
reader.readAsText(file);
|
|
475
716
|
};
|
|
717
|
+
const handleDownloadErrorCsv = () => {
|
|
718
|
+
if (!errorReport || errorReport.uid !== selectedUid || errorReport.failedRows.length === 0) {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
const { csvContent } = buildErrorCsv({
|
|
722
|
+
headers: errorReport.headers,
|
|
723
|
+
failedRows: errorReport.failedRows
|
|
724
|
+
});
|
|
725
|
+
const targetType = selectedCol?.singularName || selectedUid;
|
|
726
|
+
const errFilename = formatErrorCsvFilename(targetType);
|
|
727
|
+
downloadCsvFile(csvContent, errFilename);
|
|
728
|
+
};
|
|
476
729
|
const handleExecuteImport = async () => {
|
|
477
730
|
if (!selectedUid || allParsedRecords.length === 0) return;
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
}
|
|
482
|
-
const enrichedRecords = enrichCsvRowsWithLifecycle(allParsedRecords, currentEntries);
|
|
483
|
-
const totalRows = enrichedRecords.length;
|
|
484
|
-
const CHUNK_SIZE = 100;
|
|
485
|
-
const totalChunks = Math.ceil(totalRows / CHUNK_SIZE);
|
|
731
|
+
const runUid = selectedUid;
|
|
732
|
+
const runHeaders = originalHeaders;
|
|
733
|
+
const originalRecordsSnapshot = allParsedRecords;
|
|
486
734
|
const batchId = `csv_batch_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`;
|
|
735
|
+
activeBatchIdRef.current = batchId;
|
|
487
736
|
try {
|
|
488
737
|
setImporting(true);
|
|
489
738
|
setImportResult(null);
|
|
739
|
+
setErrorReport(null);
|
|
740
|
+
let currentEntries = collectionEntries;
|
|
741
|
+
if (currentEntries.length === 0) {
|
|
742
|
+
currentEntries = await fetchAndEnrichEntries(runUid);
|
|
743
|
+
}
|
|
744
|
+
if (activeBatchIdRef.current !== batchId) return;
|
|
745
|
+
const enrichedRecords = enrichCsvRowsWithLifecycle(originalRecordsSnapshot, currentEntries);
|
|
746
|
+
const totalRows = enrichedRecords.length;
|
|
747
|
+
const CHUNK_SIZE = 100;
|
|
748
|
+
const totalChunks = Math.ceil(totalRows / CHUNK_SIZE);
|
|
490
749
|
let liveCreated = 0;
|
|
491
750
|
let liveUpdated = 0;
|
|
492
751
|
let liveSkipped = 0;
|
|
752
|
+
let liveNewWithoutDocId = 0;
|
|
493
753
|
let liveErrors = 0;
|
|
494
754
|
let finalResultData = null;
|
|
755
|
+
const accumulatedErrors = [];
|
|
756
|
+
const accumulatedFailedRows = [];
|
|
757
|
+
const accumulatedDiffs = [];
|
|
758
|
+
const mapOriginalRowForIndex = (rowNum, backendOrigRow) => {
|
|
759
|
+
const idx = typeof rowNum === "number" ? rowNum - 2 : -1;
|
|
760
|
+
if (idx >= 0 && idx < originalRecordsSnapshot.length) {
|
|
761
|
+
return originalRecordsSnapshot[idx];
|
|
762
|
+
}
|
|
763
|
+
return backendOrigRow && typeof backendOrigRow === "object" ? backendOrigRow : {};
|
|
764
|
+
};
|
|
495
765
|
setImportProgress({
|
|
496
766
|
currentChunk: 0,
|
|
497
767
|
totalChunks,
|
|
@@ -504,53 +774,152 @@ function CsvManagerTab() {
|
|
|
504
774
|
liveErrors: 0
|
|
505
775
|
});
|
|
506
776
|
for (let chunkIdx = 0; chunkIdx < totalChunks; chunkIdx++) {
|
|
777
|
+
if (activeBatchIdRef.current !== batchId) return;
|
|
507
778
|
const startIdx = chunkIdx * CHUNK_SIZE;
|
|
508
779
|
const endIdx = Math.min(startIdx + CHUNK_SIZE, totalRows);
|
|
509
780
|
const chunkRows = enrichedRecords.slice(startIdx, endIdx);
|
|
510
781
|
const isFirst = chunkIdx === 0;
|
|
511
782
|
const isLast = chunkIdx === totalChunks - 1;
|
|
512
783
|
const startRowNumber = startIdx + 2;
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
784
|
+
try {
|
|
785
|
+
const res = await post("/bulk-updater/csv/import-chunk", {
|
|
786
|
+
uid: runUid,
|
|
787
|
+
rows: chunkRows,
|
|
788
|
+
batchId,
|
|
789
|
+
isFirstChunk: isFirst,
|
|
790
|
+
isLastChunk: isLast,
|
|
791
|
+
startRowNumber,
|
|
792
|
+
mode: importMode,
|
|
793
|
+
publish: publishOnImport,
|
|
794
|
+
publishStrategy,
|
|
795
|
+
unreviewedConsent,
|
|
796
|
+
...isFirst && runHeaders.length > 0 ? { originalHeaders: runHeaders } : {}
|
|
797
|
+
});
|
|
798
|
+
if (activeBatchIdRef.current !== batchId) return;
|
|
799
|
+
if (!res.data || !res.data.success) {
|
|
800
|
+
throw new Error(res.data?.error || `Chunk ${chunkIdx + 1} failed to process`);
|
|
801
|
+
}
|
|
802
|
+
const chunkStats = res.data.chunkStats;
|
|
803
|
+
if (chunkStats) {
|
|
804
|
+
liveCreated += chunkStats.created || 0;
|
|
805
|
+
liveUpdated += chunkStats.updated || 0;
|
|
806
|
+
liveSkipped += chunkStats.skipped || 0;
|
|
807
|
+
liveNewWithoutDocId += chunkStats.newWithoutDocId || 0;
|
|
808
|
+
liveErrors += chunkStats.errors?.length || 0;
|
|
809
|
+
if (Array.isArray(chunkStats.errors)) {
|
|
810
|
+
accumulatedErrors.push(...chunkStats.errors);
|
|
811
|
+
}
|
|
812
|
+
if (Array.isArray(chunkStats.failedRows) && chunkStats.failedRows.length > 0) {
|
|
813
|
+
for (const f of chunkStats.failedRows) {
|
|
814
|
+
accumulatedFailedRows.push({
|
|
815
|
+
row: f.row,
|
|
816
|
+
documentId: f.documentId,
|
|
817
|
+
error: f.error,
|
|
818
|
+
originalRow: mapOriginalRowForIndex(f.row, f.originalRow)
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
} else if (Array.isArray(chunkStats.errors) && chunkStats.errors.length > 0) {
|
|
822
|
+
for (const errItem of chunkStats.errors) {
|
|
823
|
+
accumulatedFailedRows.push({
|
|
824
|
+
row: errItem.row,
|
|
825
|
+
documentId: errItem.documentId,
|
|
826
|
+
error: errItem.error,
|
|
827
|
+
originalRow: mapOriginalRowForIndex(errItem.row)
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (Array.isArray(chunkStats.diffs)) {
|
|
832
|
+
accumulatedDiffs.push(...chunkStats.diffs);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
const currentProgressPercent = Math.round((chunkIdx + 1) / totalChunks * 100);
|
|
836
|
+
setImportProgress({
|
|
837
|
+
currentChunk: chunkIdx + 1,
|
|
838
|
+
totalChunks,
|
|
839
|
+
percent: currentProgressPercent,
|
|
840
|
+
processedRows: endIdx,
|
|
841
|
+
totalRows,
|
|
842
|
+
liveCreated,
|
|
843
|
+
liveUpdated,
|
|
844
|
+
liveSkipped,
|
|
845
|
+
liveErrors
|
|
846
|
+
});
|
|
847
|
+
if (isLast) {
|
|
848
|
+
finalResultData = res.data;
|
|
849
|
+
}
|
|
850
|
+
} catch (chunkErr) {
|
|
851
|
+
if (ValidationRulesTab.isAbortError(chunkErr)) return;
|
|
852
|
+
if (activeBatchIdRef.current !== batchId) return;
|
|
853
|
+
const apiErrMsg = sanitizeUserErrorMessage(
|
|
854
|
+
chunkErr?.response?.data?.error?.message || chunkErr?.response?.data?.error || chunkErr?.message || `Chunk ${chunkIdx + 1} failed to process`
|
|
855
|
+
);
|
|
856
|
+
for (let j = startIdx; j < endIdx; j++) {
|
|
857
|
+
const rowNum = j + 2;
|
|
858
|
+
const rawRow = originalRecordsSnapshot[j] || {};
|
|
859
|
+
const rowDocId = extractDocId(rawRow) || void 0;
|
|
860
|
+
accumulatedErrors.push({
|
|
861
|
+
row: rowNum,
|
|
862
|
+
...rowDocId ? { documentId: rowDocId } : {},
|
|
863
|
+
error: apiErrMsg
|
|
864
|
+
});
|
|
865
|
+
accumulatedFailedRows.push({
|
|
866
|
+
row: rowNum,
|
|
867
|
+
...rowDocId ? { documentId: rowDocId } : {},
|
|
868
|
+
error: apiErrMsg,
|
|
869
|
+
originalRow: rawRow
|
|
870
|
+
});
|
|
871
|
+
liveSkipped++;
|
|
872
|
+
liveErrors++;
|
|
873
|
+
}
|
|
874
|
+
setImportResult({
|
|
875
|
+
success: false,
|
|
876
|
+
batchId,
|
|
877
|
+
stats: {
|
|
878
|
+
total: totalRows,
|
|
879
|
+
created: liveCreated,
|
|
880
|
+
updated: liveUpdated,
|
|
881
|
+
skipped: liveSkipped,
|
|
882
|
+
newWithoutDocId: liveNewWithoutDocId,
|
|
883
|
+
errors: accumulatedErrors,
|
|
884
|
+
diffs: accumulatedDiffs
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
if (accumulatedFailedRows.length > 0) {
|
|
888
|
+
setErrorReport({
|
|
889
|
+
uid: runUid,
|
|
890
|
+
batchId,
|
|
891
|
+
headers: runHeaders,
|
|
892
|
+
failedRows: accumulatedFailedRows
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
throw new Error(apiErrMsg);
|
|
549
896
|
}
|
|
550
897
|
}
|
|
898
|
+
if (activeBatchIdRef.current !== batchId) return;
|
|
551
899
|
if (finalResultData && finalResultData.stats) {
|
|
552
900
|
setImportResult(finalResultData);
|
|
553
901
|
const stats = finalResultData.stats;
|
|
902
|
+
const finalFailedRows = accumulatedFailedRows.length > 0 ? accumulatedFailedRows : Array.isArray(stats.failedRows) && stats.failedRows.length > 0 ? stats.failedRows.map((f) => ({
|
|
903
|
+
row: f.row,
|
|
904
|
+
documentId: f.documentId,
|
|
905
|
+
error: f.error,
|
|
906
|
+
originalRow: mapOriginalRowForIndex(f.row, f.originalRow)
|
|
907
|
+
})) : Array.isArray(stats.errors) ? stats.errors.map((errItem) => ({
|
|
908
|
+
row: errItem.row,
|
|
909
|
+
documentId: errItem.documentId,
|
|
910
|
+
error: errItem.error,
|
|
911
|
+
originalRow: mapOriginalRowForIndex(errItem.row)
|
|
912
|
+
})) : [];
|
|
913
|
+
if (finalFailedRows.length > 0) {
|
|
914
|
+
setErrorReport({
|
|
915
|
+
uid: runUid,
|
|
916
|
+
batchId: finalResultData.batchId || batchId,
|
|
917
|
+
headers: runHeaders,
|
|
918
|
+
failedRows: finalFailedRows
|
|
919
|
+
});
|
|
920
|
+
} else {
|
|
921
|
+
setErrorReport(null);
|
|
922
|
+
}
|
|
554
923
|
let notifMsg = `CSV Import complete: ${stats.created} created, ${stats.updated} updated across ${stats.total} records.`;
|
|
555
924
|
if (stats.newWithoutDocId && stats.newWithoutDocId > 0) {
|
|
556
925
|
notifMsg += ` (${stats.newWithoutDocId} new entries created due to omitted documentId)`;
|
|
@@ -567,7 +936,9 @@ function CsvManagerTab() {
|
|
|
567
936
|
message: err.message || "Error processing CSV import batch"
|
|
568
937
|
});
|
|
569
938
|
} finally {
|
|
570
|
-
|
|
939
|
+
if (activeBatchIdRef.current === batchId || activeBatchIdRef.current === null) {
|
|
940
|
+
setImporting(false);
|
|
941
|
+
}
|
|
571
942
|
}
|
|
572
943
|
};
|
|
573
944
|
const handleRunPreflight = async () => {
|
|
@@ -677,23 +1048,15 @@ function CsvManagerTab() {
|
|
|
677
1048
|
{
|
|
678
1049
|
value: selectedUid || void 0,
|
|
679
1050
|
autocomplete: { type: "list", filter: "contains" },
|
|
680
|
-
placeholder: "
|
|
1051
|
+
placeholder: "Select Collection Type...",
|
|
681
1052
|
disabled: loadingCollections,
|
|
682
1053
|
clearLabel: "Clear collection selection",
|
|
683
|
-
onClear: () =>
|
|
684
|
-
setSelectedUid("");
|
|
685
|
-
setImportResult(null);
|
|
686
|
-
setImportProgress(null);
|
|
687
|
-
},
|
|
1054
|
+
onClear: () => handleCollectionChange(""),
|
|
688
1055
|
onFocus: (e) => {
|
|
689
1056
|
e.target.select();
|
|
690
1057
|
},
|
|
691
1058
|
onChange: (val) => {
|
|
692
|
-
|
|
693
|
-
setSelectedUid(val);
|
|
694
|
-
setImportResult(null);
|
|
695
|
-
setImportProgress(null);
|
|
696
|
-
}
|
|
1059
|
+
handleCollectionChange(val ? String(val) : "");
|
|
697
1060
|
},
|
|
698
1061
|
children: collections.map((col) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.ComboboxOption, { value: col.uid, textValue: `${col.displayName} (${col.uid})`, children: [
|
|
699
1062
|
col.displayName,
|
|
@@ -719,7 +1082,139 @@ function CsvManagerTab() {
|
|
|
719
1082
|
] }) }),
|
|
720
1083
|
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 5, background: "neutral100", hasRadius: true, children: [
|
|
721
1084
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h3", fontWeight: "bold", marginBottom: 2, children: "1. Export Data to CSV" }),
|
|
722
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", marginBottom: 4, children: "Extract entire collections without artificial limits (streams 10,000+ records in paged chunks) or pinpoint records violating validation quotas." }),
|
|
1085
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", marginBottom: 4, children: "Extract entire collections or filtered subsets without artificial limits (streams 10,000+ records in paged chunks) or pinpoint records violating validation quotas." }),
|
|
1086
|
+
selectedUid ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 4, background: "neutral0", hasRadius: true, marginBottom: 4, style: { border: "1px solid #eaeaef" }, children: [
|
|
1087
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 3, children: [
|
|
1088
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral700", textTransform: "uppercase", children: "Search & Filter Collection Before Export" }),
|
|
1089
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", children: [
|
|
1090
|
+
countLoading ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { backgroundColor: "neutral150", textColor: "neutral700", size: "S", children: "Calculating matching records..." }) : matchingCount !== null ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1091
|
+
designSystem.Badge,
|
|
1092
|
+
{
|
|
1093
|
+
backgroundColor: matchingCount > 0 ? "success100" : "warning100",
|
|
1094
|
+
textColor: matchingCount > 0 ? "success700" : "warning700",
|
|
1095
|
+
size: "S",
|
|
1096
|
+
children: [
|
|
1097
|
+
matchingCount.toLocaleString(),
|
|
1098
|
+
" matching records found"
|
|
1099
|
+
]
|
|
1100
|
+
}
|
|
1101
|
+
) : null,
|
|
1102
|
+
(searchAttribute || filterOperator !== "none" || entrySearch.trim()) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1103
|
+
designSystem.Button,
|
|
1104
|
+
{
|
|
1105
|
+
variant: "ghost",
|
|
1106
|
+
size: "S",
|
|
1107
|
+
onClick: () => {
|
|
1108
|
+
setSearchAttribute("");
|
|
1109
|
+
setFilterOperator("none");
|
|
1110
|
+
setFilterQuery("");
|
|
1111
|
+
setEntrySearch("");
|
|
1112
|
+
},
|
|
1113
|
+
children: "Clear Filters"
|
|
1114
|
+
}
|
|
1115
|
+
)
|
|
1116
|
+
] })
|
|
1117
|
+
] }),
|
|
1118
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, alignItems: "flex-end", wrap: "wrap", children: [
|
|
1119
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { width: 280, minWidth: 230 }, children: [
|
|
1120
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", marginBottom: 1, display: "block", children: "Search Attribute" }),
|
|
1121
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1122
|
+
designSystem.Combobox,
|
|
1123
|
+
{
|
|
1124
|
+
autocomplete: { type: "list", filter: "contains" },
|
|
1125
|
+
placeholder: "Select Search Attribute...",
|
|
1126
|
+
value: searchAttribute || void 0,
|
|
1127
|
+
clearLabel: "Reset search attribute",
|
|
1128
|
+
onClear: () => setSearchAttribute(""),
|
|
1129
|
+
onFocus: (e) => {
|
|
1130
|
+
e.target.select();
|
|
1131
|
+
},
|
|
1132
|
+
onChange: (val) => {
|
|
1133
|
+
if (val && typeof val === "string" && val !== "__none__") {
|
|
1134
|
+
setSearchAttribute(val);
|
|
1135
|
+
}
|
|
1136
|
+
},
|
|
1137
|
+
children: (selectedCol?.attributes || []).map((attr) => {
|
|
1138
|
+
const rel = relationsMeta[attr];
|
|
1139
|
+
const depth = getAttrDepth(attr);
|
|
1140
|
+
const badgeText = rel ? `relation ${rel.targetDisplayName}` : depth > 0 ? `L${depth} component` : "";
|
|
1141
|
+
const textValue = badgeText ? `${attr} ${badgeText}` : attr;
|
|
1142
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.ComboboxOption, { value: attr, textValue, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", width: "100%", gap: 2, children: [
|
|
1143
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: attr === searchAttribute ? "bold" : "regular", children: attr }),
|
|
1144
|
+
rel ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: "secondary100", textColor: "secondary700", size: "S", children: [
|
|
1145
|
+
"relation ➔ ",
|
|
1146
|
+
rel.targetDisplayName
|
|
1147
|
+
] }) : depth > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: depth === 1 ? "neutral150" : depth === 2 ? "primary100" : "secondary100", textColor: depth === 1 ? "neutral700" : depth === 2 ? "primary700" : "secondary700", size: "S", children: [
|
|
1148
|
+
"L",
|
|
1149
|
+
depth,
|
|
1150
|
+
" component"
|
|
1151
|
+
] }) : null
|
|
1152
|
+
] }) }, `search_${attr}`);
|
|
1153
|
+
})
|
|
1154
|
+
},
|
|
1155
|
+
`csv-search-attr-${selectedUid}`
|
|
1156
|
+
)
|
|
1157
|
+
] }),
|
|
1158
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { width: 200, minWidth: 170 }, children: [
|
|
1159
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", marginBottom: 1, display: "block", children: searchAttribute ? `Condition for "${searchAttribute}"` : "Filter condition" }),
|
|
1160
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1161
|
+
designSystem.SingleSelect,
|
|
1162
|
+
{
|
|
1163
|
+
value: filterOperator,
|
|
1164
|
+
disabled: !searchAttribute,
|
|
1165
|
+
onChange: (val) => setFilterOperator(String(val)),
|
|
1166
|
+
children: [
|
|
1167
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "none", children: "Show All (No Value Filter)" }),
|
|
1168
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "empty", children: "Is Empty or Null" }),
|
|
1169
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "not_empty", children: "Is Not Empty" }),
|
|
1170
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "equals", children: "Equals Exact Text" }),
|
|
1171
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "contains", children: "Contains Substring" }),
|
|
1172
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "starts_with", children: "Starts With" })
|
|
1173
|
+
]
|
|
1174
|
+
}
|
|
1175
|
+
)
|
|
1176
|
+
] }),
|
|
1177
|
+
(filterOperator === "equals" || filterOperator === "contains" || filterOperator === "starts_with") && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: 1, minWidth: 200 }, children: [
|
|
1178
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", marginBottom: 1, display: "block", children: searchAttribute ? `Value for "${searchAttribute}"` : "Value to match" }),
|
|
1179
|
+
searchAttribute && relationsMeta[searchAttribute] ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1180
|
+
designSystem.Combobox,
|
|
1181
|
+
{
|
|
1182
|
+
autocomplete: { type: "list", filter: "contains" },
|
|
1183
|
+
placeholder: searchRelationOptionsLoading ? "Loading entities..." : `Search & pick ${relationsMeta[searchAttribute].targetDisplayName} or type text...`,
|
|
1184
|
+
value: filterQuery,
|
|
1185
|
+
onClear: () => setFilterQuery(""),
|
|
1186
|
+
onChange: (val) => {
|
|
1187
|
+
if (typeof val === "string") {
|
|
1188
|
+
setFilterQuery(val);
|
|
1189
|
+
}
|
|
1190
|
+
},
|
|
1191
|
+
onInputChange: (e) => {
|
|
1192
|
+
setFilterQuery(e.target.value);
|
|
1193
|
+
},
|
|
1194
|
+
children: searchRelationOptions.map((opt) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.ComboboxOption, { value: opt.label, textValue: opt.label, children: opt.label }, opt.documentId))
|
|
1195
|
+
}
|
|
1196
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1197
|
+
designSystem.TextInput,
|
|
1198
|
+
{
|
|
1199
|
+
placeholder: "Type value to match...",
|
|
1200
|
+
value: filterQuery,
|
|
1201
|
+
onChange: (e) => setFilterQuery(e.target.value)
|
|
1202
|
+
}
|
|
1203
|
+
)
|
|
1204
|
+
] }),
|
|
1205
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: 1, minWidth: 200 }, children: [
|
|
1206
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", marginBottom: 1, display: "block", children: "Full-text Entry Search" }),
|
|
1207
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1208
|
+
designSystem.TextInput,
|
|
1209
|
+
{
|
|
1210
|
+
placeholder: "Search title, name, or text across records...",
|
|
1211
|
+
value: entrySearch,
|
|
1212
|
+
onChange: (e) => setEntrySearch(e.target.value)
|
|
1213
|
+
}
|
|
1214
|
+
)
|
|
1215
|
+
] })
|
|
1216
|
+
] })
|
|
1217
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 4, background: "neutral0", hasRadius: true, marginBottom: 4, style: { border: "1px solid #eaeaef", textAlign: "center" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", children: "Please select a Target Collection Type above to configure search filters and export data." }) }),
|
|
723
1218
|
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 4, wrap: "wrap", alignItems: "flex-end", marginTop: 3, children: [
|
|
724
1219
|
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { width: 220 }, children: [
|
|
725
1220
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", marginBottom: 1, display: "block", children: "Records to Download" }),
|
|
@@ -772,9 +1267,9 @@ function CsvManagerTab() {
|
|
|
772
1267
|
variant: "default",
|
|
773
1268
|
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Download, {}),
|
|
774
1269
|
onClick: handleExportCollection,
|
|
775
|
-
disabled: !selectedUid || exportingCollection,
|
|
1270
|
+
disabled: !selectedUid || exportingCollection || matchingCount === 0,
|
|
776
1271
|
loading: exportingCollection,
|
|
777
|
-
children: exportingCollection ? "Preparing CSV download..." : `Export ${exportLimit === 0 ? "All" : exportLimit.toLocaleString()} ${selectedCol?.displayName || "Collection"} Records (.csv)`
|
|
1272
|
+
children: exportingCollection ? "Preparing CSV download..." : countLoading ? "Export (...) Records (.csv)" : matchingCount !== null ? exportLimit > 0 && matchingCount > exportLimit ? `Export First ${exportLimit.toLocaleString()} of (${matchingCount.toLocaleString()}) Records (.csv)` : `Export (${matchingCount.toLocaleString()}) ${selectedCol?.displayName || "Collection"} Records (.csv)` : `Export ${exportLimit === 0 ? "All" : exportLimit.toLocaleString()} ${selectedCol?.displayName || "Collection"} Records (.csv)`
|
|
778
1273
|
}
|
|
779
1274
|
),
|
|
780
1275
|
rules.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", style: { marginLeft: "auto" }, children: [
|
|
@@ -855,6 +1350,7 @@ function CsvManagerTab() {
|
|
|
855
1350
|
type: "file",
|
|
856
1351
|
accept: ".csv",
|
|
857
1352
|
id: "csv-file-input",
|
|
1353
|
+
ref: fileInputRef,
|
|
858
1354
|
style: { display: "none" },
|
|
859
1355
|
onChange: handleFileUpload
|
|
860
1356
|
}
|
|
@@ -1214,6 +1710,25 @@ function CsvManagerTab() {
|
|
|
1214
1710
|
importResult.stats.errors.length - 10,
|
|
1215
1711
|
" more error",
|
|
1216
1712
|
importResult.stats.errors.length - 10 > 1 ? "s" : ""
|
|
1713
|
+
] }),
|
|
1714
|
+
errorReport && errorReport.uid === selectedUid && (!importResult.batchId || errorReport.batchId === importResult.batchId) && errorReport.failedRows.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { marginTop: 3, gap: 2, alignItems: "center", wrap: "wrap", children: [
|
|
1715
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1716
|
+
designSystem.Button,
|
|
1717
|
+
{
|
|
1718
|
+
variant: "danger-light",
|
|
1719
|
+
size: "S",
|
|
1720
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Download, {}),
|
|
1721
|
+
onClick: handleDownloadErrorCsv,
|
|
1722
|
+
children: [
|
|
1723
|
+
"Download Error CSV (",
|
|
1724
|
+
errorReport.failedRows.length.toLocaleString(),
|
|
1725
|
+
" failed row",
|
|
1726
|
+
errorReport.failedRows.length > 1 ? "s" : "",
|
|
1727
|
+
")"
|
|
1728
|
+
]
|
|
1729
|
+
}
|
|
1730
|
+
),
|
|
1731
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: "Contains only failed rows with all original columns preserved and an Error column." })
|
|
1217
1732
|
] })
|
|
1218
1733
|
] }),
|
|
1219
1734
|
importResult.stats.diffs && importResult.stats.diffs.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { marginTop: 3, padding: 3, background: "neutral0", hasRadius: true, style: { border: "1px solid #dcdce4" }, children: [
|
|
@@ -3735,24 +4250,8 @@ const BulkUpdater = () => {
|
|
|
3735
4250
|
const MODELS_CACHE_KEY = "strapi_bulk_updater_models_cache";
|
|
3736
4251
|
const LAST_ATTR_KEY = "strapi_bulk_updater_last_attr";
|
|
3737
4252
|
const LAST_COLLECTION_KEY = "strapi_bulk_updater_last_collection";
|
|
3738
|
-
const
|
|
3739
|
-
|
|
3740
|
-
const stored = localStorage.getItem(LAST_COLLECTION_KEY);
|
|
3741
|
-
if (stored) return stored;
|
|
3742
|
-
} catch {
|
|
3743
|
-
}
|
|
3744
|
-
return "";
|
|
3745
|
-
};
|
|
3746
|
-
const [selectedCollectionUid, setSelectedCollectionUid] = React.useState(getInitialCollectionUid);
|
|
3747
|
-
const getInitialAttribute = () => {
|
|
3748
|
-
try {
|
|
3749
|
-
const stored = localStorage.getItem(LAST_ATTR_KEY);
|
|
3750
|
-
if (stored) return stored;
|
|
3751
|
-
} catch {
|
|
3752
|
-
}
|
|
3753
|
-
return "";
|
|
3754
|
-
};
|
|
3755
|
-
const [selectedAttribute, setSelectedAttribute] = React.useState(getInitialAttribute);
|
|
4253
|
+
const [selectedCollectionUid, setSelectedCollectionUid] = React.useState("");
|
|
4254
|
+
const [selectedAttribute, setSelectedAttribute] = React.useState("");
|
|
3756
4255
|
const [attributeValue, setAttributeValue] = React.useState("");
|
|
3757
4256
|
const [selectedEntries, setSelectedEntries] = React.useState({});
|
|
3758
4257
|
const [expandedDzEntries, setExpandedDzEntries] = React.useState({});
|
|
@@ -3826,6 +4325,7 @@ const BulkUpdater = () => {
|
|
|
3826
4325
|
const [filterOperator, setFilterOperator] = React.useState("none");
|
|
3827
4326
|
const [filterQuery, setFilterQuery] = React.useState("");
|
|
3828
4327
|
const [entrySearch, setEntrySearch] = React.useState("");
|
|
4328
|
+
const abortControllersRef = React.useRef({});
|
|
3829
4329
|
const [statusFilter, setStatusFilter] = React.useState("all");
|
|
3830
4330
|
const isFilterActive = Boolean(searchAttribute && searchAttribute !== selectedAttribute) || filterOperator !== "none" && (["empty", "not_empty"].includes(filterOperator) || Boolean(filterQuery.trim())) || Boolean(entrySearch.trim()) || Boolean(statusFilter !== "all") || Boolean(useRegex && regexPattern.trim());
|
|
3831
4331
|
const [lastResults, setLastResults] = React.useState(null);
|
|
@@ -3937,28 +4437,14 @@ const BulkUpdater = () => {
|
|
|
3937
4437
|
setAttributesMeta(data.attributesMeta);
|
|
3938
4438
|
}
|
|
3939
4439
|
let resolvedColUid = selectedCollectionUid;
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
storedCol = localStorage.getItem(LAST_COLLECTION_KEY);
|
|
3943
|
-
} catch {
|
|
3944
|
-
}
|
|
3945
|
-
if (!resolvedColUid || !cols.some((c) => c.uid === resolvedColUid)) {
|
|
3946
|
-
resolvedColUid = storedCol && cols.some((c) => c.uid === storedCol) ? storedCol : cols[0]?.uid || "";
|
|
4440
|
+
if (resolvedColUid && !cols.some((c) => c.uid === resolvedColUid)) {
|
|
4441
|
+
resolvedColUid = "";
|
|
3947
4442
|
}
|
|
3948
4443
|
setSelectedCollectionUid(resolvedColUid);
|
|
3949
|
-
|
|
3950
|
-
if (resolvedColUid) localStorage.setItem(LAST_COLLECTION_KEY, resolvedColUid);
|
|
3951
|
-
} catch {
|
|
3952
|
-
}
|
|
3953
|
-
const activeCol = cols.find((c) => c.uid === resolvedColUid) || cols[0];
|
|
4444
|
+
const activeCol = resolvedColUid ? cols.find((c) => c.uid === resolvedColUid) : null;
|
|
3954
4445
|
const activeAttrs = activeCol?.attributes || [];
|
|
3955
4446
|
setAttributes(activeAttrs);
|
|
3956
|
-
|
|
3957
|
-
try {
|
|
3958
|
-
storedAttr = localStorage.getItem(LAST_ATTR_KEY);
|
|
3959
|
-
} catch {
|
|
3960
|
-
}
|
|
3961
|
-
const resolvedAttr = storedAttr && activeAttrs.includes(storedAttr) ? storedAttr : selectedAttribute && activeAttrs.includes(selectedAttribute) ? selectedAttribute : "";
|
|
4447
|
+
const resolvedAttr = selectedAttribute && activeAttrs.includes(selectedAttribute) ? selectedAttribute : "";
|
|
3962
4448
|
setSelectedAttribute(resolvedAttr);
|
|
3963
4449
|
if (resolvedAttr && data.relationsMeta && data.relationsMeta[resolvedAttr]) {
|
|
3964
4450
|
fetchRelationOptions(data.relationsMeta[resolvedAttr].targetUid);
|
|
@@ -4039,7 +4525,14 @@ const BulkUpdater = () => {
|
|
|
4039
4525
|
params.set("sortField", sortField);
|
|
4040
4526
|
params.set("sortOrder", sortOrder);
|
|
4041
4527
|
}
|
|
4042
|
-
|
|
4528
|
+
if (abortControllersRef.current[colUid]) {
|
|
4529
|
+
abortControllersRef.current[colUid].abort();
|
|
4530
|
+
}
|
|
4531
|
+
const controller = new AbortController();
|
|
4532
|
+
abortControllersRef.current[colUid] = controller;
|
|
4533
|
+
const res = await get(`/bulk-updater/collections/${colUid}/entries?${params.toString()}`, {
|
|
4534
|
+
signal: controller.signal
|
|
4535
|
+
});
|
|
4043
4536
|
if (res.data && (res.data.success || res.data.entries !== void 0)) {
|
|
4044
4537
|
const fetchedEntries = res.data.entries || [];
|
|
4045
4538
|
const pageNum = res.data.pagination?.page ?? targetPage ?? 1;
|
|
@@ -4181,6 +4674,9 @@ const BulkUpdater = () => {
|
|
|
4181
4674
|
}, [collections, selectedCollectionUid]);
|
|
4182
4675
|
const handleCollectionChange = (newUid) => {
|
|
4183
4676
|
if (newUid === selectedCollectionUid) return;
|
|
4677
|
+
if (abortControllersRef.current) {
|
|
4678
|
+
Object.values(abortControllersRef.current).forEach((ctrl) => ctrl.abort());
|
|
4679
|
+
}
|
|
4184
4680
|
setSelectedCollectionUid(newUid);
|
|
4185
4681
|
try {
|
|
4186
4682
|
if (newUid) {
|
|
@@ -4270,59 +4766,40 @@ const BulkUpdater = () => {
|
|
|
4270
4766
|
});
|
|
4271
4767
|
}, [depthFilteredAttributes, relationsMeta, selectedAttribute, componentDepth, attributesMeta]);
|
|
4272
4768
|
const memoizedSearchComboboxOptions = React.useMemo(() => {
|
|
4273
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
}
|
|
4288
|
-
),
|
|
4289
|
-
|
|
4290
|
-
const rel = relationsMeta[attr];
|
|
4291
|
-
const depth = getAttrDepth(attr);
|
|
4292
|
-
const badgeText = rel ? `relation ${rel.targetDisplayName}` : depth > 0 ? `L${depth} component` : "";
|
|
4293
|
-
const textValue = badgeText ? `${attr} ${badgeText}` : attr;
|
|
4294
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.ComboboxOption, { value: attr, textValue, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", width: "100%", gap: 2, children: [
|
|
4295
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: attr === searchAttribute ? "bold" : "regular", children: attr }),
|
|
4296
|
-
rel ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: "secondary100", textColor: "secondary700", size: "S", children: [
|
|
4297
|
-
"relation ➔ ",
|
|
4298
|
-
rel.targetDisplayName
|
|
4299
|
-
] }) : depth > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: depth === 1 ? "neutral150" : depth === 2 ? "primary100" : "secondary100", textColor: depth === 1 ? "neutral700" : depth === 2 ? "primary700" : "secondary700", size: "S", children: [
|
|
4300
|
-
"L",
|
|
4301
|
-
depth,
|
|
4302
|
-
" component"
|
|
4303
|
-
] }) : null
|
|
4304
|
-
] }) }, `search_${attr}`);
|
|
4305
|
-
})
|
|
4306
|
-
] });
|
|
4769
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: depthFilteredAttributes.map((attr) => {
|
|
4770
|
+
const rel = relationsMeta[attr];
|
|
4771
|
+
const depth = getAttrDepth(attr);
|
|
4772
|
+
const badgeText = rel ? `relation ${rel.targetDisplayName}` : depth > 0 ? `L${depth} component` : "";
|
|
4773
|
+
const textValue = badgeText ? `${attr} ${badgeText}` : attr;
|
|
4774
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.ComboboxOption, { value: attr, textValue, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", width: "100%", gap: 2, children: [
|
|
4775
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: attr === searchAttribute ? "bold" : "regular", children: attr }),
|
|
4776
|
+
rel ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: "secondary100", textColor: "secondary700", size: "S", children: [
|
|
4777
|
+
"relation ➔ ",
|
|
4778
|
+
rel.targetDisplayName
|
|
4779
|
+
] }) : depth > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: depth === 1 ? "neutral150" : depth === 2 ? "primary100" : "secondary100", textColor: depth === 1 ? "neutral700" : depth === 2 ? "primary700" : "secondary700", size: "S", children: [
|
|
4780
|
+
"L",
|
|
4781
|
+
depth,
|
|
4782
|
+
" component"
|
|
4783
|
+
] }) : null
|
|
4784
|
+
] }) }, `search_${attr}`);
|
|
4785
|
+
}) });
|
|
4307
4786
|
}, [depthFilteredAttributes, relationsMeta, searchAttribute, selectedAttribute, componentDepth, attributesMeta]);
|
|
4308
4787
|
const handleSearchAttributeChange = (newAttr) => {
|
|
4309
4788
|
const finalAttr = newAttr === "__default__" ? "" : newAttr;
|
|
4310
4789
|
setSearchAttribute(finalAttr);
|
|
4311
|
-
if (
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
);
|
|
4325
|
-
});
|
|
4790
|
+
if (selectedCollectionUid) {
|
|
4791
|
+
loadCollectionPage(
|
|
4792
|
+
selectedCollectionUid,
|
|
4793
|
+
1,
|
|
4794
|
+
void 0,
|
|
4795
|
+
void 0,
|
|
4796
|
+
void 0,
|
|
4797
|
+
filterOperator,
|
|
4798
|
+
filterQuery,
|
|
4799
|
+
entrySearch,
|
|
4800
|
+
true,
|
|
4801
|
+
finalAttr
|
|
4802
|
+
);
|
|
4326
4803
|
}
|
|
4327
4804
|
};
|
|
4328
4805
|
const handleCollectionPageSizeChange = (colUid, newSize) => {
|
|
@@ -5418,7 +5895,7 @@ const BulkUpdater = () => {
|
|
|
5418
5895
|
designSystem.Combobox,
|
|
5419
5896
|
{
|
|
5420
5897
|
autocomplete: { type: "list", filter: "contains" },
|
|
5421
|
-
placeholder: "
|
|
5898
|
+
placeholder: "Select Collection Type...",
|
|
5422
5899
|
value: selectedCollectionUid || void 0,
|
|
5423
5900
|
clearLabel: "Clear collection selection",
|
|
5424
5901
|
onClear: () => handleCollectionChange(""),
|
|
@@ -5519,8 +5996,8 @@ const BulkUpdater = () => {
|
|
|
5519
5996
|
designSystem.Combobox,
|
|
5520
5997
|
{
|
|
5521
5998
|
autocomplete: { type: "list", filter: "contains" },
|
|
5522
|
-
placeholder:
|
|
5523
|
-
value: searchAttribute ||
|
|
5999
|
+
placeholder: "Select Search Attribute...",
|
|
6000
|
+
value: searchAttribute || void 0,
|
|
5524
6001
|
clearLabel: "Reset search attribute",
|
|
5525
6002
|
onClear: () => handleSearchAttributeChange(""),
|
|
5526
6003
|
onFocus: (e) => {
|
|
@@ -5539,8 +6016,9 @@ const BulkUpdater = () => {
|
|
|
5539
6016
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { width: 200, minWidth: 170 }, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5540
6017
|
designSystem.SingleSelect,
|
|
5541
6018
|
{
|
|
5542
|
-
label:
|
|
6019
|
+
label: searchAttribute ? `Condition for "${searchAttribute}"` : "Filter condition",
|
|
5543
6020
|
value: filterOperator,
|
|
6021
|
+
disabled: !searchAttribute,
|
|
5544
6022
|
onChange: (val) => setFilterOperator(String(val)),
|
|
5545
6023
|
children: [
|
|
5546
6024
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "none", children: "Show All (No Value Filter)" }),
|
|
@@ -6308,7 +6786,7 @@ const BulkUpdater = () => {
|
|
|
6308
6786
|
designSystem.Combobox,
|
|
6309
6787
|
{
|
|
6310
6788
|
autocomplete: { type: "list", filter: "contains" },
|
|
6311
|
-
placeholder: "
|
|
6789
|
+
placeholder: "Select Attribute to Update...",
|
|
6312
6790
|
value: selectedAttribute || void 0,
|
|
6313
6791
|
clearLabel: "Clear attribute selection",
|
|
6314
6792
|
onClear: () => handleAttributeChange(""),
|
|
@@ -7711,4 +8189,4 @@ exports.getNestedValue = getNestedValue;
|
|
|
7711
8189
|
exports.getPropertyValue = getPropertyValue;
|
|
7712
8190
|
exports.getSortOptionsForCollection = getSortOptionsForCollection;
|
|
7713
8191
|
exports.parseDynamicZonePath = parseDynamicZonePath;
|
|
7714
|
-
//# sourceMappingURL=BulkUpdater-
|
|
8192
|
+
//# sourceMappingURL=BulkUpdater-C7-KHLWq.js.map
|