strapi-plugin-bulk-updater 1.5.15 → 1.6.0
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-DljSFIEd.mjs → BulkUpdater-CTKfvKhE.mjs} +2481 -441
- package/dist/_chunks/BulkUpdater-CTKfvKhE.mjs.map +1 -0
- package/dist/_chunks/{BulkUpdater-CrmdSFUB.js → BulkUpdater-D12SUhTd.js} +2479 -439
- package/dist/_chunks/BulkUpdater-D12SUhTd.js.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +6239 -4788
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +6239 -4788
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/_chunks/BulkUpdater-CrmdSFUB.js.map +0 -1
- package/dist/_chunks/BulkUpdater-DljSFIEd.mjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import React__default, { useRef, useState, useEffect, useMemo } from "react";
|
|
3
3
|
import { useFetchClient, useNotification } from "@strapi/strapi/admin";
|
|
4
|
-
import { Box, Flex, Typography, Button, Combobox, ComboboxOption, Badge, SingleSelect, SingleSelectOption, TextInput, Checkbox, Alert, Table, Thead, Tr, Th, Tbody, Td, Loader, Field } from "@strapi/design-system";
|
|
5
|
-
import { ArrowClockwise, Download, Upload, ChevronLeft, ChevronRight, Eye, Check, Cog, Play } from "@strapi/icons";
|
|
4
|
+
import { Box, Flex, Typography, Button, Combobox, ComboboxOption, Badge, SingleSelect, SingleSelectOption, TextInput, Checkbox, Alert, Table, Thead, Tr, Th, Tbody, Td, Loader, Textarea, Field } from "@strapi/design-system";
|
|
5
|
+
import { ArrowClockwise, Download, Upload, ChevronLeft, ChevronRight, Eye, Check, Search, Cog, Play } from "@strapi/icons";
|
|
6
6
|
import { i as isAbortError, V as ValidationRulesTab } from "./ValidationRulesTab-BtOCWK8E.mjs";
|
|
7
7
|
function parseCsvRows(csvText) {
|
|
8
8
|
if (!csvText) return [];
|
|
@@ -72,10 +72,11 @@ function parseCsvRows(csvText) {
|
|
|
72
72
|
}
|
|
73
73
|
return rows;
|
|
74
74
|
}
|
|
75
|
-
function
|
|
75
|
+
function parseCsvWithHeaders(csvText) {
|
|
76
76
|
const rows = parseCsvRows(csvText);
|
|
77
|
-
if (rows.length
|
|
77
|
+
if (rows.length === 0) return { headers: [], records: [] };
|
|
78
78
|
const headers = rows[0].map((h) => h.trim());
|
|
79
|
+
if (rows.length < 2) return { headers, records: [] };
|
|
79
80
|
const records = [];
|
|
80
81
|
for (let i = 1; i < rows.length; i++) {
|
|
81
82
|
const row = rows[i];
|
|
@@ -89,7 +90,125 @@ function parseCsv(csvText) {
|
|
|
89
90
|
});
|
|
90
91
|
records.push(record);
|
|
91
92
|
}
|
|
92
|
-
return records;
|
|
93
|
+
return { headers, records };
|
|
94
|
+
}
|
|
95
|
+
function escapeCsvCell(val) {
|
|
96
|
+
if (val === null || val === void 0) return "";
|
|
97
|
+
let str = "";
|
|
98
|
+
if (val instanceof Date) {
|
|
99
|
+
str = val.toISOString();
|
|
100
|
+
} else if (typeof val === "object") {
|
|
101
|
+
str = JSON.stringify(val);
|
|
102
|
+
} else {
|
|
103
|
+
str = String(val);
|
|
104
|
+
}
|
|
105
|
+
str = str.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
106
|
+
if (/^[=+@-]/.test(str)) {
|
|
107
|
+
str = `'${str}`;
|
|
108
|
+
}
|
|
109
|
+
if (str.includes(",") || str.includes('"') || str.includes("\n") || str.includes("\r")) {
|
|
110
|
+
return `"${str.replace(/"/g, '""')}"`;
|
|
111
|
+
}
|
|
112
|
+
return str;
|
|
113
|
+
}
|
|
114
|
+
function sanitizeUserErrorMessage(msg) {
|
|
115
|
+
if (msg === null || msg === void 0) return "Error processing row";
|
|
116
|
+
const raw = typeof msg === "string" ? msg : String(msg);
|
|
117
|
+
const cleanedLines = raw.split(/\r?\n/).filter((line) => !/^\s+at\s+.+(\(.+\)|:\d+:\d+)\s*$/.test(line)).map((line) => line.trim()).filter(Boolean);
|
|
118
|
+
return cleanedLines.join(" ").trim() || "Error processing row";
|
|
119
|
+
}
|
|
120
|
+
function resolveErrorColumnName(existingHeaders) {
|
|
121
|
+
const existingLower = new Set(
|
|
122
|
+
existingHeaders.map((h) => String(h || "").trim().toLowerCase())
|
|
123
|
+
);
|
|
124
|
+
if (!existingLower.has("error")) return "Error";
|
|
125
|
+
if (!existingLower.has("import error")) return "Import Error";
|
|
126
|
+
let suffix = 2;
|
|
127
|
+
while (existingLower.has(`import error (${suffix})`)) {
|
|
128
|
+
suffix++;
|
|
129
|
+
}
|
|
130
|
+
return `Import Error (${suffix})`;
|
|
131
|
+
}
|
|
132
|
+
function formatErrorCsvFilename(collectionTypeOrUid, date = /* @__PURE__ */ new Date()) {
|
|
133
|
+
const rawSegment = collectionTypeOrUid ? String(collectionTypeOrUid).split(".").pop() || String(collectionTypeOrUid) : "collection";
|
|
134
|
+
const safeType = rawSegment.replace(/[^a-zA-Z0-9_-]+/g, "_").replace(/^_+|_+$/g, "") || "collection";
|
|
135
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
136
|
+
const stamp = `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}_${pad(
|
|
137
|
+
date.getHours()
|
|
138
|
+
)}${pad(date.getMinutes())}${pad(date.getSeconds())}`;
|
|
139
|
+
return `error_${safeType}_${stamp}.csv`;
|
|
140
|
+
}
|
|
141
|
+
function buildErrorCsv(options) {
|
|
142
|
+
const { headers, failedRows } = options || {};
|
|
143
|
+
if (!Array.isArray(failedRows) || failedRows.length === 0) {
|
|
144
|
+
return {
|
|
145
|
+
csvContent: "",
|
|
146
|
+
headers: headers ? [...headers] : [],
|
|
147
|
+
errorColumnName: "Error",
|
|
148
|
+
errorCount: 0
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const groupedByRow = /* @__PURE__ */ new Map();
|
|
152
|
+
for (const item of failedRows) {
|
|
153
|
+
if (!item || typeof item !== "object") continue;
|
|
154
|
+
const rowNum = typeof item.row === "number" && !isNaN(item.row) ? item.row : groupedByRow.size + 2;
|
|
155
|
+
const msg = sanitizeUserErrorMessage(item.error);
|
|
156
|
+
const existing = groupedByRow.get(rowNum);
|
|
157
|
+
if (existing) {
|
|
158
|
+
if (!existing.messages.includes(msg)) {
|
|
159
|
+
existing.messages.push(msg);
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
groupedByRow.set(rowNum, {
|
|
163
|
+
row: rowNum,
|
|
164
|
+
documentId: item.documentId,
|
|
165
|
+
messages: [msg],
|
|
166
|
+
originalRow: item.originalRow && typeof item.originalRow === "object" ? item.originalRow : {}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const orderedEntries = Array.from(groupedByRow.values()).sort((a, b) => a.row - b.row);
|
|
171
|
+
if (orderedEntries.length === 0) {
|
|
172
|
+
return {
|
|
173
|
+
csvContent: "",
|
|
174
|
+
headers: headers ? [...headers] : [],
|
|
175
|
+
errorColumnName: "Error",
|
|
176
|
+
errorCount: 0
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
let baseHeaders = [];
|
|
180
|
+
if (Array.isArray(headers) && headers.length > 0) {
|
|
181
|
+
baseHeaders = [...headers];
|
|
182
|
+
} else {
|
|
183
|
+
const keySet = /* @__PURE__ */ new Set();
|
|
184
|
+
for (const entry of orderedEntries) {
|
|
185
|
+
for (const k of Object.keys(entry.originalRow || {})) {
|
|
186
|
+
if (!keySet.has(k)) {
|
|
187
|
+
keySet.add(k);
|
|
188
|
+
baseHeaders.push(k);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const errorColumnName = resolveErrorColumnName(baseHeaders);
|
|
194
|
+
const finalHeaders = [...baseHeaders, errorColumnName];
|
|
195
|
+
const lines = [];
|
|
196
|
+
lines.push(finalHeaders.map(escapeCsvCell).join(","));
|
|
197
|
+
for (const entry of orderedEntries) {
|
|
198
|
+
const cells = baseHeaders.map((h) => {
|
|
199
|
+
const val = entry.originalRow ? entry.originalRow[h] : "";
|
|
200
|
+
return escapeCsvCell(val === void 0 || val === null ? "" : val);
|
|
201
|
+
});
|
|
202
|
+
cells.push(escapeCsvCell(entry.messages.join("; ")));
|
|
203
|
+
lines.push(cells.join(","));
|
|
204
|
+
}
|
|
205
|
+
const csvContent = "\uFEFF" + lines.join("\r\n") + "\r\n";
|
|
206
|
+
return {
|
|
207
|
+
csvContent,
|
|
208
|
+
headers: finalHeaders,
|
|
209
|
+
errorColumnName,
|
|
210
|
+
errorCount: orderedEntries.length
|
|
211
|
+
};
|
|
93
212
|
}
|
|
94
213
|
const LIFECYCLE_STATUS_WORDS = /* @__PURE__ */ new Set([
|
|
95
214
|
"pending review",
|
|
@@ -261,7 +380,7 @@ function CsvManagerTab() {
|
|
|
261
380
|
const [selectedRuleId, setSelectedRuleId] = useState("");
|
|
262
381
|
const [importMode, setImportMode] = useState("auto");
|
|
263
382
|
const [publishOnImport, setPublishOnImport] = useState(true);
|
|
264
|
-
const [
|
|
383
|
+
const [originalHeaders, setOriginalHeaders] = useState([]);
|
|
265
384
|
const [fileName, setFileName] = useState("");
|
|
266
385
|
const [allParsedRecords, setAllParsedRecords] = useState([]);
|
|
267
386
|
const [previewPage, setPreviewPage] = useState(1);
|
|
@@ -269,6 +388,8 @@ function CsvManagerTab() {
|
|
|
269
388
|
const [importing, setImporting] = useState(false);
|
|
270
389
|
const [importProgress, setImportProgress] = useState(null);
|
|
271
390
|
const [importResult, setImportResult] = useState(null);
|
|
391
|
+
const [errorReport, setErrorReport] = useState(null);
|
|
392
|
+
const activeBatchIdRef = useRef(null);
|
|
272
393
|
const [executionWindow, setExecutionWindow] = useState(null);
|
|
273
394
|
const [preflightLoading, setPreflightLoading] = useState(false);
|
|
274
395
|
const [preflightReport, setPreflightReport] = useState(null);
|
|
@@ -347,13 +468,15 @@ function CsvManagerTab() {
|
|
|
347
468
|
if (countAbortControllerRef.current) {
|
|
348
469
|
countAbortControllerRef.current.abort();
|
|
349
470
|
}
|
|
471
|
+
activeBatchIdRef.current = null;
|
|
350
472
|
setSelectedUid(newUid);
|
|
351
473
|
setAllParsedRecords([]);
|
|
352
|
-
|
|
474
|
+
setOriginalHeaders([]);
|
|
353
475
|
setFileName("");
|
|
354
476
|
setPreviewPage(1);
|
|
355
477
|
setImportProgress(null);
|
|
356
478
|
setImportResult(null);
|
|
479
|
+
setErrorReport(null);
|
|
357
480
|
setPreflightReport(null);
|
|
358
481
|
setPreflightLoading(false);
|
|
359
482
|
setImporting(false);
|
|
@@ -565,43 +688,76 @@ function CsvManagerTab() {
|
|
|
565
688
|
const handleFileUpload = (e) => {
|
|
566
689
|
const file = e.target.files?.[0];
|
|
567
690
|
if (!file) return;
|
|
691
|
+
activeBatchIdRef.current = null;
|
|
568
692
|
setFileName(file.name);
|
|
569
693
|
setImportResult(null);
|
|
570
694
|
setImportProgress(null);
|
|
695
|
+
setPreflightReport(null);
|
|
696
|
+
setErrorReport(null);
|
|
697
|
+
setOriginalHeaders([]);
|
|
571
698
|
const reader = new FileReader();
|
|
572
699
|
reader.onload = (event) => {
|
|
573
700
|
const text = event.target?.result;
|
|
574
|
-
setCsvRawText(text);
|
|
575
701
|
try {
|
|
576
|
-
const records =
|
|
577
|
-
|
|
578
|
-
setAllParsedRecords(
|
|
702
|
+
const { headers, records } = parseCsvWithHeaders(text);
|
|
703
|
+
setOriginalHeaders(headers);
|
|
704
|
+
setAllParsedRecords(records);
|
|
579
705
|
setPreviewPage(1);
|
|
580
706
|
} catch (err) {
|
|
707
|
+
setOriginalHeaders([]);
|
|
581
708
|
setAllParsedRecords([]);
|
|
582
709
|
}
|
|
583
710
|
};
|
|
584
711
|
reader.readAsText(file);
|
|
585
712
|
};
|
|
713
|
+
const handleDownloadErrorCsv = () => {
|
|
714
|
+
if (!errorReport || errorReport.uid !== selectedUid || errorReport.failedRows.length === 0) {
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
const { csvContent } = buildErrorCsv({
|
|
718
|
+
headers: errorReport.headers,
|
|
719
|
+
failedRows: errorReport.failedRows
|
|
720
|
+
});
|
|
721
|
+
const targetType = selectedCol?.singularName || selectedUid;
|
|
722
|
+
const errFilename = formatErrorCsvFilename(targetType);
|
|
723
|
+
downloadCsvFile(csvContent, errFilename);
|
|
724
|
+
};
|
|
586
725
|
const handleExecuteImport = async () => {
|
|
587
726
|
if (!selectedUid || allParsedRecords.length === 0) return;
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
}
|
|
592
|
-
const enrichedRecords = enrichCsvRowsWithLifecycle(allParsedRecords, currentEntries);
|
|
593
|
-
const totalRows = enrichedRecords.length;
|
|
594
|
-
const CHUNK_SIZE = 100;
|
|
595
|
-
const totalChunks = Math.ceil(totalRows / CHUNK_SIZE);
|
|
727
|
+
const runUid = selectedUid;
|
|
728
|
+
const runHeaders = originalHeaders;
|
|
729
|
+
const originalRecordsSnapshot = allParsedRecords;
|
|
596
730
|
const batchId = `csv_batch_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`;
|
|
731
|
+
activeBatchIdRef.current = batchId;
|
|
597
732
|
try {
|
|
598
733
|
setImporting(true);
|
|
599
734
|
setImportResult(null);
|
|
735
|
+
setErrorReport(null);
|
|
736
|
+
let currentEntries = collectionEntries;
|
|
737
|
+
if (currentEntries.length === 0) {
|
|
738
|
+
currentEntries = await fetchAndEnrichEntries(runUid);
|
|
739
|
+
}
|
|
740
|
+
if (activeBatchIdRef.current !== batchId) return;
|
|
741
|
+
const enrichedRecords = enrichCsvRowsWithLifecycle(originalRecordsSnapshot, currentEntries);
|
|
742
|
+
const totalRows = enrichedRecords.length;
|
|
743
|
+
const CHUNK_SIZE = 100;
|
|
744
|
+
const totalChunks = Math.ceil(totalRows / CHUNK_SIZE);
|
|
600
745
|
let liveCreated = 0;
|
|
601
746
|
let liveUpdated = 0;
|
|
602
747
|
let liveSkipped = 0;
|
|
748
|
+
let liveNewWithoutDocId = 0;
|
|
603
749
|
let liveErrors = 0;
|
|
604
750
|
let finalResultData = null;
|
|
751
|
+
const accumulatedErrors = [];
|
|
752
|
+
const accumulatedFailedRows = [];
|
|
753
|
+
const accumulatedDiffs = [];
|
|
754
|
+
const mapOriginalRowForIndex = (rowNum, backendOrigRow) => {
|
|
755
|
+
const idx = typeof rowNum === "number" ? rowNum - 2 : -1;
|
|
756
|
+
if (idx >= 0 && idx < originalRecordsSnapshot.length) {
|
|
757
|
+
return originalRecordsSnapshot[idx];
|
|
758
|
+
}
|
|
759
|
+
return backendOrigRow && typeof backendOrigRow === "object" ? backendOrigRow : {};
|
|
760
|
+
};
|
|
605
761
|
setImportProgress({
|
|
606
762
|
currentChunk: 0,
|
|
607
763
|
totalChunks,
|
|
@@ -614,53 +770,152 @@ function CsvManagerTab() {
|
|
|
614
770
|
liveErrors: 0
|
|
615
771
|
});
|
|
616
772
|
for (let chunkIdx = 0; chunkIdx < totalChunks; chunkIdx++) {
|
|
773
|
+
if (activeBatchIdRef.current !== batchId) return;
|
|
617
774
|
const startIdx = chunkIdx * CHUNK_SIZE;
|
|
618
775
|
const endIdx = Math.min(startIdx + CHUNK_SIZE, totalRows);
|
|
619
776
|
const chunkRows = enrichedRecords.slice(startIdx, endIdx);
|
|
620
777
|
const isFirst = chunkIdx === 0;
|
|
621
778
|
const isLast = chunkIdx === totalChunks - 1;
|
|
622
779
|
const startRowNumber = startIdx + 2;
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
780
|
+
try {
|
|
781
|
+
const res = await post("/bulk-updater/csv/import-chunk", {
|
|
782
|
+
uid: runUid,
|
|
783
|
+
rows: chunkRows,
|
|
784
|
+
batchId,
|
|
785
|
+
isFirstChunk: isFirst,
|
|
786
|
+
isLastChunk: isLast,
|
|
787
|
+
startRowNumber,
|
|
788
|
+
mode: importMode,
|
|
789
|
+
publish: publishOnImport,
|
|
790
|
+
publishStrategy,
|
|
791
|
+
unreviewedConsent,
|
|
792
|
+
...isFirst && runHeaders.length > 0 ? { originalHeaders: runHeaders } : {}
|
|
793
|
+
});
|
|
794
|
+
if (activeBatchIdRef.current !== batchId) return;
|
|
795
|
+
if (!res.data || !res.data.success) {
|
|
796
|
+
throw new Error(res.data?.error || `Chunk ${chunkIdx + 1} failed to process`);
|
|
797
|
+
}
|
|
798
|
+
const chunkStats = res.data.chunkStats;
|
|
799
|
+
if (chunkStats) {
|
|
800
|
+
liveCreated += chunkStats.created || 0;
|
|
801
|
+
liveUpdated += chunkStats.updated || 0;
|
|
802
|
+
liveSkipped += chunkStats.skipped || 0;
|
|
803
|
+
liveNewWithoutDocId += chunkStats.newWithoutDocId || 0;
|
|
804
|
+
liveErrors += chunkStats.errors?.length || 0;
|
|
805
|
+
if (Array.isArray(chunkStats.errors)) {
|
|
806
|
+
accumulatedErrors.push(...chunkStats.errors);
|
|
807
|
+
}
|
|
808
|
+
if (Array.isArray(chunkStats.failedRows) && chunkStats.failedRows.length > 0) {
|
|
809
|
+
for (const f of chunkStats.failedRows) {
|
|
810
|
+
accumulatedFailedRows.push({
|
|
811
|
+
row: f.row,
|
|
812
|
+
documentId: f.documentId,
|
|
813
|
+
error: f.error,
|
|
814
|
+
originalRow: mapOriginalRowForIndex(f.row, f.originalRow)
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
} else if (Array.isArray(chunkStats.errors) && chunkStats.errors.length > 0) {
|
|
818
|
+
for (const errItem of chunkStats.errors) {
|
|
819
|
+
accumulatedFailedRows.push({
|
|
820
|
+
row: errItem.row,
|
|
821
|
+
documentId: errItem.documentId,
|
|
822
|
+
error: errItem.error,
|
|
823
|
+
originalRow: mapOriginalRowForIndex(errItem.row)
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
if (Array.isArray(chunkStats.diffs)) {
|
|
828
|
+
accumulatedDiffs.push(...chunkStats.diffs);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
const currentProgressPercent = Math.round((chunkIdx + 1) / totalChunks * 100);
|
|
832
|
+
setImportProgress({
|
|
833
|
+
currentChunk: chunkIdx + 1,
|
|
834
|
+
totalChunks,
|
|
835
|
+
percent: currentProgressPercent,
|
|
836
|
+
processedRows: endIdx,
|
|
837
|
+
totalRows,
|
|
838
|
+
liveCreated,
|
|
839
|
+
liveUpdated,
|
|
840
|
+
liveSkipped,
|
|
841
|
+
liveErrors
|
|
842
|
+
});
|
|
843
|
+
if (isLast) {
|
|
844
|
+
finalResultData = res.data;
|
|
845
|
+
}
|
|
846
|
+
} catch (chunkErr) {
|
|
847
|
+
if (isAbortError(chunkErr)) return;
|
|
848
|
+
if (activeBatchIdRef.current !== batchId) return;
|
|
849
|
+
const apiErrMsg = sanitizeUserErrorMessage(
|
|
850
|
+
chunkErr?.response?.data?.error?.message || chunkErr?.response?.data?.error || chunkErr?.message || `Chunk ${chunkIdx + 1} failed to process`
|
|
851
|
+
);
|
|
852
|
+
for (let j = startIdx; j < endIdx; j++) {
|
|
853
|
+
const rowNum = j + 2;
|
|
854
|
+
const rawRow = originalRecordsSnapshot[j] || {};
|
|
855
|
+
const rowDocId = extractDocId(rawRow) || void 0;
|
|
856
|
+
accumulatedErrors.push({
|
|
857
|
+
row: rowNum,
|
|
858
|
+
...rowDocId ? { documentId: rowDocId } : {},
|
|
859
|
+
error: apiErrMsg
|
|
860
|
+
});
|
|
861
|
+
accumulatedFailedRows.push({
|
|
862
|
+
row: rowNum,
|
|
863
|
+
...rowDocId ? { documentId: rowDocId } : {},
|
|
864
|
+
error: apiErrMsg,
|
|
865
|
+
originalRow: rawRow
|
|
866
|
+
});
|
|
867
|
+
liveSkipped++;
|
|
868
|
+
liveErrors++;
|
|
869
|
+
}
|
|
870
|
+
setImportResult({
|
|
871
|
+
success: false,
|
|
872
|
+
batchId,
|
|
873
|
+
stats: {
|
|
874
|
+
total: totalRows,
|
|
875
|
+
created: liveCreated,
|
|
876
|
+
updated: liveUpdated,
|
|
877
|
+
skipped: liveSkipped,
|
|
878
|
+
newWithoutDocId: liveNewWithoutDocId,
|
|
879
|
+
errors: accumulatedErrors,
|
|
880
|
+
diffs: accumulatedDiffs
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
if (accumulatedFailedRows.length > 0) {
|
|
884
|
+
setErrorReport({
|
|
885
|
+
uid: runUid,
|
|
886
|
+
batchId,
|
|
887
|
+
headers: runHeaders,
|
|
888
|
+
failedRows: accumulatedFailedRows
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
throw new Error(apiErrMsg);
|
|
659
892
|
}
|
|
660
893
|
}
|
|
894
|
+
if (activeBatchIdRef.current !== batchId) return;
|
|
661
895
|
if (finalResultData && finalResultData.stats) {
|
|
662
896
|
setImportResult(finalResultData);
|
|
663
897
|
const stats = finalResultData.stats;
|
|
898
|
+
const finalFailedRows = accumulatedFailedRows.length > 0 ? accumulatedFailedRows : Array.isArray(stats.failedRows) && stats.failedRows.length > 0 ? stats.failedRows.map((f) => ({
|
|
899
|
+
row: f.row,
|
|
900
|
+
documentId: f.documentId,
|
|
901
|
+
error: f.error,
|
|
902
|
+
originalRow: mapOriginalRowForIndex(f.row, f.originalRow)
|
|
903
|
+
})) : Array.isArray(stats.errors) ? stats.errors.map((errItem) => ({
|
|
904
|
+
row: errItem.row,
|
|
905
|
+
documentId: errItem.documentId,
|
|
906
|
+
error: errItem.error,
|
|
907
|
+
originalRow: mapOriginalRowForIndex(errItem.row)
|
|
908
|
+
})) : [];
|
|
909
|
+
if (finalFailedRows.length > 0) {
|
|
910
|
+
setErrorReport({
|
|
911
|
+
uid: runUid,
|
|
912
|
+
batchId: finalResultData.batchId || batchId,
|
|
913
|
+
headers: runHeaders,
|
|
914
|
+
failedRows: finalFailedRows
|
|
915
|
+
});
|
|
916
|
+
} else {
|
|
917
|
+
setErrorReport(null);
|
|
918
|
+
}
|
|
664
919
|
let notifMsg = `CSV Import complete: ${stats.created} created, ${stats.updated} updated across ${stats.total} records.`;
|
|
665
920
|
if (stats.newWithoutDocId && stats.newWithoutDocId > 0) {
|
|
666
921
|
notifMsg += ` (${stats.newWithoutDocId} new entries created due to omitted documentId)`;
|
|
@@ -677,7 +932,9 @@ function CsvManagerTab() {
|
|
|
677
932
|
message: err.message || "Error processing CSV import batch"
|
|
678
933
|
});
|
|
679
934
|
} finally {
|
|
680
|
-
|
|
935
|
+
if (activeBatchIdRef.current === batchId || activeBatchIdRef.current === null) {
|
|
936
|
+
setImporting(false);
|
|
937
|
+
}
|
|
681
938
|
}
|
|
682
939
|
};
|
|
683
940
|
const handleRunPreflight = async () => {
|
|
@@ -1449,6 +1706,25 @@ function CsvManagerTab() {
|
|
|
1449
1706
|
importResult.stats.errors.length - 10,
|
|
1450
1707
|
" more error",
|
|
1451
1708
|
importResult.stats.errors.length - 10 > 1 ? "s" : ""
|
|
1709
|
+
] }),
|
|
1710
|
+
errorReport && errorReport.uid === selectedUid && (!importResult.batchId || errorReport.batchId === importResult.batchId) && errorReport.failedRows.length > 0 && /* @__PURE__ */ jsxs(Flex, { marginTop: 3, gap: 2, alignItems: "center", wrap: "wrap", children: [
|
|
1711
|
+
/* @__PURE__ */ jsxs(
|
|
1712
|
+
Button,
|
|
1713
|
+
{
|
|
1714
|
+
variant: "danger-light",
|
|
1715
|
+
size: "S",
|
|
1716
|
+
startIcon: /* @__PURE__ */ jsx(Download, {}),
|
|
1717
|
+
onClick: handleDownloadErrorCsv,
|
|
1718
|
+
children: [
|
|
1719
|
+
"Download Error CSV (",
|
|
1720
|
+
errorReport.failedRows.length.toLocaleString(),
|
|
1721
|
+
" failed row",
|
|
1722
|
+
errorReport.failedRows.length > 1 ? "s" : "",
|
|
1723
|
+
")"
|
|
1724
|
+
]
|
|
1725
|
+
}
|
|
1726
|
+
),
|
|
1727
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: "Contains only failed rows with all original columns preserved and an Error column." })
|
|
1452
1728
|
] })
|
|
1453
1729
|
] }),
|
|
1454
1730
|
importResult.stats.diffs && importResult.stats.diffs.length > 0 && /* @__PURE__ */ jsxs(Box, { marginTop: 3, padding: 3, background: "neutral0", hasRadius: true, style: { border: "1px solid #dcdce4" }, children: [
|
|
@@ -2467,6 +2743,7 @@ const BulkUpdatePreviewModal = ({
|
|
|
2467
2743
|
previewData,
|
|
2468
2744
|
attribute,
|
|
2469
2745
|
targetValueDisplay,
|
|
2746
|
+
editMode = "common",
|
|
2470
2747
|
publishOnApproval = true,
|
|
2471
2748
|
lifecycleStats
|
|
2472
2749
|
}) => {
|
|
@@ -2481,12 +2758,14 @@ const BulkUpdatePreviewModal = ({
|
|
|
2481
2758
|
if (searchQuery.trim()) {
|
|
2482
2759
|
const q = searchQuery.toLowerCase().trim();
|
|
2483
2760
|
items = items.filter(
|
|
2484
|
-
(d) => d.label.toLowerCase().includes(q) || d.documentId.toLowerCase().includes(q) || d.collectionName.toLowerCase().includes(q) || String(d.oldDisplay || "").toLowerCase().includes(q) || String(d.newDisplay || "").toLowerCase().includes(q)
|
|
2761
|
+
(d) => d.label.toLowerCase().includes(q) || d.documentId.toLowerCase().includes(q) || d.collectionName.toLowerCase().includes(q) || String(d.attribute || "").toLowerCase().includes(q) || String(d.oldDisplay || "").toLowerCase().includes(q) || String(d.newDisplay || "").toLowerCase().includes(q)
|
|
2485
2762
|
);
|
|
2486
2763
|
}
|
|
2487
2764
|
return items;
|
|
2488
2765
|
}, [previewData, filterTab, searchQuery]);
|
|
2489
2766
|
if (!isOpen) return null;
|
|
2767
|
+
const isGridMode = editMode === "grid" || previewData?.editMode === "grid";
|
|
2768
|
+
const willErrorCount = previewData?.summary?.willError || 0;
|
|
2490
2769
|
return /* @__PURE__ */ jsx(
|
|
2491
2770
|
"div",
|
|
2492
2771
|
{
|
|
@@ -2510,7 +2789,7 @@ const BulkUpdatePreviewModal = ({
|
|
|
2510
2789
|
hasRadius: true,
|
|
2511
2790
|
shadow: "popupShadow",
|
|
2512
2791
|
style: {
|
|
2513
|
-
maxWidth:
|
|
2792
|
+
maxWidth: 1120,
|
|
2514
2793
|
width: "95%",
|
|
2515
2794
|
maxHeight: "calc(100vh - 48px)",
|
|
2516
2795
|
display: "flex",
|
|
@@ -2537,13 +2816,16 @@ const BulkUpdatePreviewModal = ({
|
|
|
2537
2816
|
/* @__PURE__ */ jsxs(Badge, { backgroundColor: "primary100", textColor: "primary700", children: [
|
|
2538
2817
|
"Target: ",
|
|
2539
2818
|
attribute
|
|
2540
|
-
] })
|
|
2819
|
+
] }),
|
|
2820
|
+
isGridMode && /* @__PURE__ */ jsx(Badge, { backgroundColor: "secondary100", textColor: "secondary700", children: "GRID EDITING MODE" })
|
|
2541
2821
|
] }),
|
|
2542
2822
|
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: "Inspect exact before & after values across target records before applying changes to the database." })
|
|
2543
2823
|
] }),
|
|
2544
2824
|
/* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", wrap: "wrap", children: [
|
|
2545
|
-
/* @__PURE__ */
|
|
2546
|
-
|
|
2825
|
+
!isGridMode ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2826
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: "New Value:" }),
|
|
2827
|
+
/* @__PURE__ */ jsx(Badge, { backgroundColor: "success100", textColor: "success700", children: targetValueDisplay || "(empty)" })
|
|
2828
|
+
] }) : /* @__PURE__ */ jsx(Badge, { backgroundColor: "secondary100", textColor: "secondary700", children: targetValueDisplay || "Per-Record & Component Grid Edits" }),
|
|
2547
2829
|
/* @__PURE__ */ jsx(
|
|
2548
2830
|
Badge,
|
|
2549
2831
|
{
|
|
@@ -2571,6 +2853,13 @@ const BulkUpdatePreviewModal = ({
|
|
|
2571
2853
|
/* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "semiBold", children: "Inspecting Target Records..." }),
|
|
2572
2854
|
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: "Computing proposed diffs and verifying against database schema." })
|
|
2573
2855
|
] }) }) : !previewData ? /* @__PURE__ */ jsx(Box, { padding: 6, style: { textAlign: "center" }, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: "No preview data available." }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2856
|
+
willErrorCount > 0 && /* @__PURE__ */ jsx(Box, { marginBottom: 4, padding: 3, background: "danger100", hasRadius: true, style: { border: "1px solid #f5c0b8" }, children: /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
|
|
2857
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "bold", textColor: "danger700", children: "⚠️ Validation / Quota Violation Detected:" }),
|
|
2858
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "danger700", children: [
|
|
2859
|
+
willErrorCount,
|
|
2860
|
+
' item(s) failed schema or quota validation rules. Inspect the rows marked "Validation Error" below; invalid records will be rejected during batch execution and retained for editing.'
|
|
2861
|
+
] })
|
|
2862
|
+
] }) }),
|
|
2574
2863
|
publishOnApproval && lifecycleStats && lifecycleStats.unreviewedCount > 0 && /* @__PURE__ */ jsx(Box, { marginBottom: 4, padding: 3, background: "warning100", hasRadius: true, style: { border: "1px solid #f5c0b8" }, children: /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
|
|
2575
2864
|
/* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "bold", textColor: "warning700", children: "⚠️ Safe Publishing Active:" }),
|
|
2576
2865
|
/* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "warning700", children: [
|
|
@@ -2636,7 +2925,7 @@ const BulkUpdatePreviewModal = ({
|
|
|
2636
2925
|
variant: "sigma",
|
|
2637
2926
|
textColor: previewData.summary.skipped > 0 ? "warning700" : "neutral600",
|
|
2638
2927
|
display: "block",
|
|
2639
|
-
children: "WILL SKIP
|
|
2928
|
+
children: "WILL SKIP"
|
|
2640
2929
|
}
|
|
2641
2930
|
),
|
|
2642
2931
|
/* @__PURE__ */ jsx(
|
|
@@ -2650,6 +2939,19 @@ const BulkUpdatePreviewModal = ({
|
|
|
2650
2939
|
)
|
|
2651
2940
|
]
|
|
2652
2941
|
}
|
|
2942
|
+
),
|
|
2943
|
+
willErrorCount > 0 && /* @__PURE__ */ jsxs(
|
|
2944
|
+
Box,
|
|
2945
|
+
{
|
|
2946
|
+
padding: 3,
|
|
2947
|
+
background: "danger100",
|
|
2948
|
+
hasRadius: true,
|
|
2949
|
+
style: { flex: 1, minWidth: 140, border: "1px solid #ffa39e" },
|
|
2950
|
+
children: [
|
|
2951
|
+
/* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "danger700", display: "block", children: "VALIDATION ERRORS" }),
|
|
2952
|
+
/* @__PURE__ */ jsx(Typography, { variant: "beta", fontWeight: "bold", textColor: "danger700", children: willErrorCount })
|
|
2953
|
+
]
|
|
2954
|
+
}
|
|
2653
2955
|
)
|
|
2654
2956
|
] }),
|
|
2655
2957
|
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 3, wrap: "wrap", gap: 3, children: [
|
|
@@ -2662,7 +2964,7 @@ const BulkUpdatePreviewModal = ({
|
|
|
2662
2964
|
onClick: () => setFilterTab("all"),
|
|
2663
2965
|
children: [
|
|
2664
2966
|
"All (",
|
|
2665
|
-
previewData.summary.total,
|
|
2967
|
+
isGridMode ? previewData.diffs.length : previewData.summary.total,
|
|
2666
2968
|
")"
|
|
2667
2969
|
]
|
|
2668
2970
|
}
|
|
@@ -2705,6 +3007,19 @@ const BulkUpdatePreviewModal = ({
|
|
|
2705
3007
|
")"
|
|
2706
3008
|
]
|
|
2707
3009
|
}
|
|
3010
|
+
),
|
|
3011
|
+
willErrorCount > 0 && /* @__PURE__ */ jsxs(
|
|
3012
|
+
Button,
|
|
3013
|
+
{
|
|
3014
|
+
variant: filterTab === "will_error" ? "default" : "tertiary",
|
|
3015
|
+
size: "S",
|
|
3016
|
+
onClick: () => setFilterTab("will_error"),
|
|
3017
|
+
children: [
|
|
3018
|
+
"Errors (",
|
|
3019
|
+
willErrorCount,
|
|
3020
|
+
")"
|
|
3021
|
+
]
|
|
3022
|
+
}
|
|
2708
3023
|
)
|
|
2709
3024
|
] }),
|
|
2710
3025
|
/* @__PURE__ */ jsx(Box, { style: { width: 260 }, children: /* @__PURE__ */ jsx(
|
|
@@ -2727,20 +3042,22 @@ const BulkUpdatePreviewModal = ({
|
|
|
2727
3042
|
overflowY: "auto",
|
|
2728
3043
|
overflowX: "auto"
|
|
2729
3044
|
},
|
|
2730
|
-
children: /* @__PURE__ */ jsxs(Table, { colCount:
|
|
3045
|
+
children: /* @__PURE__ */ jsxs(Table, { colCount: 6, rowCount: filteredDiffs.length + 1, style: { width: "100%", minWidth: 880 }, children: [
|
|
2731
3046
|
/* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
|
|
2732
|
-
/* @__PURE__ */ jsx(Th, { style: { width:
|
|
2733
|
-
/* @__PURE__ */ jsx(Th, { style: { minWidth:
|
|
2734
|
-
/* @__PURE__ */ jsx(Th, { style: { minWidth:
|
|
2735
|
-
/* @__PURE__ */ jsx(Th, { style: { minWidth:
|
|
2736
|
-
/* @__PURE__ */ jsx(Th, { style: {
|
|
3047
|
+
/* @__PURE__ */ jsx(Th, { style: { width: 140 }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: "COLLECTION" }) }),
|
|
3048
|
+
/* @__PURE__ */ jsx(Th, { style: { minWidth: 185 }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: "RECORD IDENTIFIER" }) }),
|
|
3049
|
+
/* @__PURE__ */ jsx(Th, { style: { minWidth: 165 }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: "ATTRIBUTE / BLOCK" }) }),
|
|
3050
|
+
/* @__PURE__ */ jsx(Th, { style: { minWidth: 170 }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: "CURRENT VALUE (BEFORE)" }) }),
|
|
3051
|
+
/* @__PURE__ */ jsx(Th, { style: { minWidth: 170 }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: "NEW VALUE (AFTER)" }) }),
|
|
3052
|
+
/* @__PURE__ */ jsx(Th, { style: { width: 150, textAlign: "right" }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: "IMPACT" }) })
|
|
2737
3053
|
] }) }),
|
|
2738
|
-
/* @__PURE__ */ jsx(Tbody, { children: filteredDiffs.length === 0 ? /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(Td, { colSpan:
|
|
3054
|
+
/* @__PURE__ */ jsx(Tbody, { children: filteredDiffs.length === 0 ? /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(Td, { colSpan: 6, style: { textAlign: "center", padding: "24px" }, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: "No records match the current filter or search criteria." }) }) }) : filteredDiffs.map((diff, idx) => /* @__PURE__ */ jsxs(Tr, { children: [
|
|
2739
3055
|
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Badge, { backgroundColor: "neutral150", textColor: "neutral700", children: diff.collectionName }) }),
|
|
2740
3056
|
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Box, { children: [
|
|
2741
3057
|
/* @__PURE__ */ jsx(Typography, { fontWeight: "bold", display: "block", children: diff.label }),
|
|
2742
3058
|
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: /* @__PURE__ */ jsx("code", { children: diff.documentId }) })
|
|
2743
3059
|
] }) }),
|
|
3060
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "semiBold", textColor: "primary700", children: diff.attribute || attribute }) }),
|
|
2744
3061
|
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(
|
|
2745
3062
|
Typography,
|
|
2746
3063
|
{
|
|
@@ -2753,13 +3070,14 @@ const BulkUpdatePreviewModal = ({
|
|
|
2753
3070
|
children: diff.oldDisplay || "(empty)"
|
|
2754
3071
|
}
|
|
2755
3072
|
) }),
|
|
2756
|
-
/* @__PURE__ */ jsx(Td, { children: diff.status === "will_skip" ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "warning700", children: "— Skipped (field absent) —" }) : diff.hasChange ? /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", textColor: "success700", style: { wordBreak: "break-all" }, children: diff.newDisplay || "(empty)" }) : /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", children: diff.newDisplay || "(already matching)" }) }),
|
|
3073
|
+
/* @__PURE__ */ jsx(Td, { children: diff.status === "will_error" ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger700", fontWeight: "bold", children: diff.validationError || diff.message }) : diff.status === "will_skip" ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "warning700", children: "— Skipped (field absent) —" }) : diff.hasChange ? /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", textColor: "success700", style: { wordBreak: "break-all" }, children: diff.newDisplay || "(empty)" }) : /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", children: diff.newDisplay || "(already matching)" }) }),
|
|
2757
3074
|
/* @__PURE__ */ jsxs(Td, { style: { textAlign: "right" }, children: [
|
|
2758
3075
|
diff.status === "will_update" && /* @__PURE__ */ jsx(Badge, { backgroundColor: "success100", textColor: "success700", children: "✓ Will Update" }),
|
|
2759
3076
|
diff.status === "unchanged" && /* @__PURE__ */ jsx(Badge, { backgroundColor: "neutral150", textColor: "neutral600", children: "= Unchanged" }),
|
|
2760
|
-
diff.status === "will_skip" && /* @__PURE__ */ jsx(Badge, { backgroundColor: "warning100", textColor: "warning700", children: "⚠ Will Skip" })
|
|
3077
|
+
diff.status === "will_skip" && /* @__PURE__ */ jsx(Badge, { backgroundColor: "warning100", textColor: "warning700", children: "⚠ Will Skip" }),
|
|
3078
|
+
diff.status === "will_error" && /* @__PURE__ */ jsx(Badge, { backgroundColor: "danger100", textColor: "danger700", children: "✕ Error" })
|
|
2761
3079
|
] })
|
|
2762
|
-
] }, `${diff.uid}-${diff.documentId}`)) })
|
|
3080
|
+
] }, `${diff.uid}-${diff.documentId}-${diff.attribute || "root"}-${idx}`)) })
|
|
2763
3081
|
] })
|
|
2764
3082
|
}
|
|
2765
3083
|
)
|
|
@@ -2787,7 +3105,7 @@ const BulkUpdatePreviewModal = ({
|
|
|
2787
3105
|
onClose();
|
|
2788
3106
|
onProceed();
|
|
2789
3107
|
},
|
|
2790
|
-
disabled: loading || !previewData || previewData.summary.total === 0,
|
|
3108
|
+
disabled: loading || !previewData || previewData.summary.total === 0 || isGridMode && previewData.summary.willUpdate === 0,
|
|
2791
3109
|
children: [
|
|
2792
3110
|
"Proceed to Execute (",
|
|
2793
3111
|
previewData?.summary.willUpdate || 0,
|
|
@@ -3226,12 +3544,13 @@ const CheckerReviewModal = ({
|
|
|
3226
3544
|
children: diff.oldDisplay || "(empty)"
|
|
3227
3545
|
}
|
|
3228
3546
|
) }),
|
|
3229
|
-
/* @__PURE__ */ jsx(Td, { children: diff.status === "will_create" ? /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", textColor: "success700", style: { wordBreak: "break-all" }, children: diff.newDisplay || "(new value)" }) : diff.status === "will_skip" ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "warning700", children: "— Skipped —" }) : diff.hasChange ? /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", textColor: "success700", style: { wordBreak: "break-all" }, children: diff.newDisplay || "(empty)" }) : /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", children: diff.newDisplay || "(matching)" }) }),
|
|
3547
|
+
/* @__PURE__ */ jsx(Td, { children: diff.status === "will_create" ? /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", textColor: "success700", style: { wordBreak: "break-all" }, children: diff.newDisplay || "(new value)" }) : diff.status === "will_error" ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger700", fontWeight: "bold", children: diff.validationError || diff.message || "Validation error" }) : diff.status === "will_skip" ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "warning700", children: "— Skipped —" }) : diff.hasChange ? /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", textColor: "success700", style: { wordBreak: "break-all" }, children: diff.newDisplay || "(empty)" }) : /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", children: diff.newDisplay || "(matching)" }) }),
|
|
3230
3548
|
/* @__PURE__ */ jsxs(Td, { style: { textAlign: "right" }, children: [
|
|
3231
3549
|
diff.status === "will_create" && /* @__PURE__ */ jsx(Badge, { backgroundColor: "success100", textColor: "success700", children: "+ Will Create" }),
|
|
3232
3550
|
diff.status === "will_update" && /* @__PURE__ */ jsx(Badge, { backgroundColor: "warning100", textColor: "warning700", children: "✎ Will Update" }),
|
|
3233
3551
|
diff.status === "unchanged" && /* @__PURE__ */ jsx(Badge, { backgroundColor: "neutral150", textColor: "neutral600", children: "= Unchanged" }),
|
|
3234
|
-
diff.status === "will_skip" && /* @__PURE__ */ jsx(Badge, { backgroundColor: "
|
|
3552
|
+
diff.status === "will_skip" && /* @__PURE__ */ jsx(Badge, { backgroundColor: "warning100", textColor: "warning700", children: "⚠ Will Skip" }),
|
|
3553
|
+
diff.status === "will_error" && /* @__PURE__ */ jsx(Badge, { backgroundColor: "danger100", textColor: "danger700", children: "✕ Validation Error" })
|
|
3235
3554
|
] })
|
|
3236
3555
|
] }, `${diff.uid}-${diff.documentId}-${diff.attribute}-${idx}`)) })
|
|
3237
3556
|
] })
|
|
@@ -3309,14 +3628,19 @@ const CheckerReviewModal = ({
|
|
|
3309
3628
|
}
|
|
3310
3629
|
);
|
|
3311
3630
|
};
|
|
3312
|
-
function
|
|
3631
|
+
function formatComponentNameFriendly(compUid) {
|
|
3632
|
+
if (!compUid) return "Component";
|
|
3633
|
+
const name = compUid.includes(".") ? compUid.split(".")[1] : compUid;
|
|
3634
|
+
return name.split(/[-_]/).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3635
|
+
}
|
|
3636
|
+
function parseAttrPathClient(path) {
|
|
3313
3637
|
if (!path) return { cleanPath: "", rootKey: "", subPath: "" };
|
|
3314
|
-
const bracketMatch = path.match(/^([^.[]+)\[([^\]]+)\]
|
|
3638
|
+
const bracketMatch = path.match(/^([^.[]+)\[([^\]]+)\](?:\.(.+))?$/);
|
|
3315
3639
|
if (bracketMatch) {
|
|
3316
3640
|
const rootKey = bracketMatch[1];
|
|
3317
|
-
const selector = bracketMatch[2];
|
|
3318
|
-
const subPath = bracketMatch[3];
|
|
3319
|
-
const cleanPath = `${rootKey}.${subPath}
|
|
3641
|
+
const selector = bracketMatch[2].trim();
|
|
3642
|
+
const subPath = bracketMatch[3] || "";
|
|
3643
|
+
const cleanPath = subPath ? `${rootKey}.${subPath}` : rootKey;
|
|
3320
3644
|
if (/^\d+$/.test(selector)) {
|
|
3321
3645
|
return { cleanPath, rootKey, subPath, targetIndex: parseInt(selector, 10) };
|
|
3322
3646
|
}
|
|
@@ -3329,126 +3653,1410 @@ function parseDynamicZonePath(path) {
|
|
|
3329
3653
|
subPath: parts.slice(1).join(".")
|
|
3330
3654
|
};
|
|
3331
3655
|
}
|
|
3332
|
-
function
|
|
3333
|
-
if (!
|
|
3334
|
-
|
|
3335
|
-
|
|
3656
|
+
function buildOccurrenceKey(segments) {
|
|
3657
|
+
if (!segments || segments.length === 0) return "__scalar__";
|
|
3658
|
+
return segments.map((seg) => {
|
|
3659
|
+
if (seg.index !== void 0) {
|
|
3660
|
+
return seg.componentId !== void 0 && seg.componentId !== null ? `${seg.key}[${seg.index}#${seg.componentId}]` : `${seg.key}[${seg.index}]`;
|
|
3661
|
+
}
|
|
3662
|
+
return seg.key;
|
|
3663
|
+
}).join(".");
|
|
3336
3664
|
}
|
|
3337
|
-
function
|
|
3338
|
-
if (!
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3665
|
+
function buildReadablePath(segments) {
|
|
3666
|
+
if (!segments || segments.length === 0) return "";
|
|
3667
|
+
return segments.map((seg) => {
|
|
3668
|
+
if (seg.index !== void 0) {
|
|
3669
|
+
const label = seg.componentUid ? ` ${formatComponentNameFriendly(seg.componentUid)}` : "";
|
|
3670
|
+
return `${seg.key}[#${seg.index}${label}]`;
|
|
3671
|
+
}
|
|
3672
|
+
return seg.key;
|
|
3673
|
+
}).join(".");
|
|
3674
|
+
}
|
|
3675
|
+
function getDirectProp(obj, key) {
|
|
3676
|
+
if (!obj || typeof obj !== "object") return void 0;
|
|
3677
|
+
if (obj[key] !== void 0) return obj[key];
|
|
3678
|
+
const camel = key.replace(/_([a-z0-9])/g, (_, l) => l.toUpperCase());
|
|
3679
|
+
if (obj[camel] !== void 0) return obj[camel];
|
|
3680
|
+
const snake = key.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
3681
|
+
if (obj[snake] !== void 0) return obj[snake];
|
|
3682
|
+
return void 0;
|
|
3683
|
+
}
|
|
3684
|
+
function resolveTailExistsOrValue(obj, parts) {
|
|
3685
|
+
let cur = obj;
|
|
3686
|
+
for (const p of parts) {
|
|
3687
|
+
if (cur === null || cur === void 0) return void 0;
|
|
3688
|
+
if (Array.isArray(cur)) {
|
|
3689
|
+
for (const item of cur) {
|
|
3690
|
+
const found = resolveTailExistsOrValue(item, parts.slice(parts.indexOf(p)));
|
|
3691
|
+
if (found !== void 0) return found;
|
|
3361
3692
|
}
|
|
3362
|
-
|
|
3363
|
-
|
|
3693
|
+
return void 0;
|
|
3694
|
+
}
|
|
3695
|
+
cur = getDirectProp(cur, p);
|
|
3364
3696
|
}
|
|
3365
|
-
|
|
3366
|
-
|
|
3697
|
+
return cur;
|
|
3698
|
+
}
|
|
3699
|
+
function enumerateClientOccurrences(entry, attrPath, availableAttributes, attrMeta) {
|
|
3700
|
+
if (!entry || !attrPath) return [];
|
|
3701
|
+
const parsed = parseAttrPathClient(attrPath);
|
|
3702
|
+
const parts = parsed.cleanPath.split(".").filter(Boolean);
|
|
3703
|
+
if (parts.length === 0) return [];
|
|
3704
|
+
if (parts.length === 1 && !parsed.targetComponentUid && parsed.targetIndex === void 0) {
|
|
3705
|
+
const val = getDirectProp(entry, parts[0]);
|
|
3367
3706
|
return [
|
|
3368
3707
|
{
|
|
3708
|
+
occurrenceKey: "__scalar__",
|
|
3709
|
+
displayPath: parts[0],
|
|
3710
|
+
segments: [{ key: parts[0] }],
|
|
3711
|
+
value: val !== void 0 ? val : null,
|
|
3369
3712
|
index: 0,
|
|
3370
|
-
|
|
3371
|
-
path: parsed.cleanPath
|
|
3713
|
+
isMissingIntermediate: false
|
|
3372
3714
|
}
|
|
3373
3715
|
];
|
|
3374
3716
|
}
|
|
3375
|
-
|
|
3717
|
+
const results = [];
|
|
3718
|
+
function walk(currentVal, remainingParts, segments, missingIntermediate, firstArrayIndex, resolvedCompUid, resolvedCompId, isRootLevel) {
|
|
3719
|
+
if (remainingParts.length === 0) return;
|
|
3720
|
+
const [head, ...tail] = remainingParts;
|
|
3721
|
+
if (tail.length === 0) {
|
|
3722
|
+
const val = currentVal && typeof currentVal === "object" ? getDirectProp(currentVal, head) : void 0;
|
|
3723
|
+
const nextSegs = [...segments, { key: head }];
|
|
3724
|
+
results.push({
|
|
3725
|
+
occurrenceKey: buildOccurrenceKey(nextSegs),
|
|
3726
|
+
displayPath: buildReadablePath(nextSegs),
|
|
3727
|
+
segments: nextSegs,
|
|
3728
|
+
value: val !== void 0 ? val : null,
|
|
3729
|
+
componentUid: resolvedCompUid,
|
|
3730
|
+
componentName: resolvedCompUid ? formatComponentNameFriendly(resolvedCompUid) : void 0,
|
|
3731
|
+
componentId: resolvedCompId,
|
|
3732
|
+
index: firstArrayIndex ?? 0,
|
|
3733
|
+
isMissingIntermediate: missingIntermediate
|
|
3734
|
+
});
|
|
3735
|
+
return;
|
|
3736
|
+
}
|
|
3737
|
+
const nextVal = currentVal && typeof currentVal === "object" ? getDirectProp(currentVal, head) : void 0;
|
|
3738
|
+
const isExpectingRootArray = isRootLevel && (attrMeta?.rootType === "dynamiczone" || attrMeta?.rootRepeatable);
|
|
3739
|
+
if (Array.isArray(nextVal)) {
|
|
3740
|
+
const subPath = tail.join(".");
|
|
3741
|
+
nextVal.forEach((item, idx) => {
|
|
3742
|
+
if (!item || typeof item !== "object") return;
|
|
3743
|
+
if (isRootLevel && parsed.targetIndex !== void 0 && idx !== parsed.targetIndex) return;
|
|
3744
|
+
if (isRootLevel && parsed.targetComponentUid && item.__component !== parsed.targetComponentUid) return;
|
|
3745
|
+
if (item.__component && isRootLevel) {
|
|
3746
|
+
const scopedAttr = `${head}[${item.__component}].${subPath}`;
|
|
3747
|
+
const supportedBySchema = Array.isArray(availableAttributes) && availableAttributes.includes(scopedAttr);
|
|
3748
|
+
const presentInData = resolveTailExistsOrValue(item, tail) !== void 0;
|
|
3749
|
+
if (!supportedBySchema && !presentInData) {
|
|
3750
|
+
return;
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
const seg2 = {
|
|
3754
|
+
key: head,
|
|
3755
|
+
index: idx,
|
|
3756
|
+
componentId: item.id,
|
|
3757
|
+
componentUid: item.__component || (isRootLevel ? attrMeta?.component : void 0)
|
|
3758
|
+
};
|
|
3759
|
+
walk(
|
|
3760
|
+
item,
|
|
3761
|
+
tail,
|
|
3762
|
+
[...segments, seg2],
|
|
3763
|
+
missingIntermediate,
|
|
3764
|
+
firstArrayIndex ?? idx,
|
|
3765
|
+
item.__component || resolvedCompUid,
|
|
3766
|
+
resolvedCompId ?? item.id,
|
|
3767
|
+
false
|
|
3768
|
+
);
|
|
3769
|
+
});
|
|
3770
|
+
return;
|
|
3771
|
+
}
|
|
3772
|
+
if (isExpectingRootArray) {
|
|
3773
|
+
return;
|
|
3774
|
+
}
|
|
3775
|
+
const isMissing = !nextVal || typeof nextVal !== "object";
|
|
3776
|
+
const seg = {
|
|
3777
|
+
key: head,
|
|
3778
|
+
componentId: !isMissing ? nextVal.id : void 0,
|
|
3779
|
+
componentUid: !isMissing && nextVal.__component ? nextVal.__component : void 0
|
|
3780
|
+
};
|
|
3781
|
+
walk(
|
|
3782
|
+
isMissing ? void 0 : nextVal,
|
|
3783
|
+
tail,
|
|
3784
|
+
[...segments, seg],
|
|
3785
|
+
missingIntermediate || isMissing,
|
|
3786
|
+
firstArrayIndex,
|
|
3787
|
+
resolvedCompUid,
|
|
3788
|
+
resolvedCompId,
|
|
3789
|
+
false
|
|
3790
|
+
);
|
|
3791
|
+
}
|
|
3792
|
+
walk(entry, parts, [], false, void 0, void 0, void 0, true);
|
|
3793
|
+
return results;
|
|
3376
3794
|
}
|
|
3377
|
-
function
|
|
3378
|
-
if (
|
|
3379
|
-
if (
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
const
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3795
|
+
function normalizeDisplayCompareValue(v) {
|
|
3796
|
+
if (v === void 0 || v === null) return null;
|
|
3797
|
+
if (typeof v === "object" && v.isRelation) return v;
|
|
3798
|
+
return v;
|
|
3799
|
+
}
|
|
3800
|
+
function areClientValuesEqual(a, b) {
|
|
3801
|
+
const na = normalizeDisplayCompareValue(a);
|
|
3802
|
+
const nb = normalizeDisplayCompareValue(b);
|
|
3803
|
+
if (na === nb) return true;
|
|
3804
|
+
if (na === null || nb === null) return na === nb;
|
|
3805
|
+
if (typeof na === "object" || typeof nb === "object") {
|
|
3806
|
+
try {
|
|
3807
|
+
return JSON.stringify(na) === JSON.stringify(nb);
|
|
3808
|
+
} catch {
|
|
3809
|
+
return false;
|
|
3810
|
+
}
|
|
3392
3811
|
}
|
|
3393
|
-
|
|
3394
|
-
if (camelKey in target) return target[camelKey];
|
|
3395
|
-
if (snakeKey in target) return target[snakeKey];
|
|
3396
|
-
return void 0;
|
|
3812
|
+
return String(na) === String(nb);
|
|
3397
3813
|
}
|
|
3398
|
-
function
|
|
3399
|
-
if (
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3814
|
+
function extractRelationEditCommand(rawVal, currentDisplayVal, isMulti = false) {
|
|
3815
|
+
if (rawVal && typeof rawVal === "object" && !Array.isArray(rawVal) && rawVal.mode) {
|
|
3816
|
+
return {
|
|
3817
|
+
mode: rawVal.mode,
|
|
3818
|
+
documentIds: Array.isArray(rawVal.documentIds) ? rawVal.documentIds : rawVal.documentId ? [rawVal.documentId] : [],
|
|
3819
|
+
label: rawVal.label || ""
|
|
3820
|
+
};
|
|
3821
|
+
}
|
|
3822
|
+
if (Array.isArray(rawVal)) {
|
|
3823
|
+
return {
|
|
3824
|
+
mode: "set",
|
|
3825
|
+
documentIds: rawVal.map((r) => r?.documentId).filter(Boolean),
|
|
3826
|
+
label: rawVal.map((r) => r?.name || r?.title || r?.email || r?.documentId).filter(Boolean).join(", ")
|
|
3827
|
+
};
|
|
3828
|
+
}
|
|
3829
|
+
if (rawVal && typeof rawVal === "object" && rawVal.documentId) {
|
|
3830
|
+
return {
|
|
3831
|
+
mode: "set",
|
|
3832
|
+
documentIds: [rawVal.documentId],
|
|
3833
|
+
label: rawVal.name || rawVal.title || rawVal.email || rawVal.documentId
|
|
3834
|
+
};
|
|
3835
|
+
}
|
|
3836
|
+
if (typeof rawVal === "string") {
|
|
3837
|
+
try {
|
|
3838
|
+
const parsed = JSON.parse(rawVal);
|
|
3839
|
+
if (parsed && typeof parsed === "object" && parsed.mode) {
|
|
3840
|
+
return {
|
|
3841
|
+
mode: parsed.mode,
|
|
3842
|
+
documentIds: Array.isArray(parsed.documentIds) ? parsed.documentIds : [],
|
|
3843
|
+
label: parsed.label || ""
|
|
3844
|
+
};
|
|
3416
3845
|
}
|
|
3417
|
-
|
|
3846
|
+
} catch {
|
|
3418
3847
|
}
|
|
3419
|
-
return extract(getPropertyValue(current, head), tail);
|
|
3420
3848
|
}
|
|
3421
|
-
|
|
3849
|
+
if (currentDisplayVal) {
|
|
3850
|
+
return extractRelationEditCommand(currentDisplayVal, void 0, isMulti);
|
|
3851
|
+
}
|
|
3852
|
+
return { mode: "clear", documentIds: [], label: "" };
|
|
3422
3853
|
}
|
|
3423
|
-
function
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3854
|
+
function validateClientFieldValue(value, attrMeta) {
|
|
3855
|
+
if (!attrMeta) return null;
|
|
3856
|
+
const type = String(attrMeta.type || "").toLowerCase();
|
|
3857
|
+
const isEmpty = value === null || value === void 0 || value === "";
|
|
3858
|
+
if (attrMeta.required && isEmpty && type !== "boolean") {
|
|
3859
|
+
return "Required field";
|
|
3860
|
+
}
|
|
3861
|
+
if (attrMeta.required && type === "boolean" && (value === null || value === void 0 || value === "")) {
|
|
3862
|
+
return "Required boolean";
|
|
3863
|
+
}
|
|
3864
|
+
if (isEmpty) return null;
|
|
3865
|
+
switch (type) {
|
|
3866
|
+
case "integer":
|
|
3867
|
+
case "biginteger": {
|
|
3868
|
+
const s = String(value).trim();
|
|
3869
|
+
if (!/^-?\d+$/.test(s)) return "Must be a valid integer";
|
|
3870
|
+
if (type === "integer") {
|
|
3871
|
+
const n = Number(s);
|
|
3872
|
+
if (!Number.isSafeInteger(n)) return "Integer out of range";
|
|
3873
|
+
if (typeof attrMeta.min === "number" && n < attrMeta.min) return `Min ${attrMeta.min}`;
|
|
3874
|
+
if (typeof attrMeta.max === "number" && n > attrMeta.max) return `Max ${attrMeta.max}`;
|
|
3875
|
+
}
|
|
3876
|
+
return null;
|
|
3436
3877
|
}
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3878
|
+
case "float":
|
|
3879
|
+
case "decimal": {
|
|
3880
|
+
const s = String(value).trim();
|
|
3881
|
+
if (!/^-?\d+(\.\d+)?$/.test(s)) return "Must be a valid number";
|
|
3882
|
+
const n = Number(s);
|
|
3883
|
+
if (typeof attrMeta.min === "number" && n < attrMeta.min) return `Min ${attrMeta.min}`;
|
|
3884
|
+
if (typeof attrMeta.max === "number" && n > attrMeta.max) return `Max ${attrMeta.max}`;
|
|
3885
|
+
return null;
|
|
3442
3886
|
}
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
}
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3887
|
+
case "boolean": {
|
|
3888
|
+
if (typeof value === "boolean") return null;
|
|
3889
|
+
const lower = String(value).trim().toLowerCase();
|
|
3890
|
+
if (!["true", "false", "1", "0"].includes(lower)) return "Must be true or false";
|
|
3891
|
+
return null;
|
|
3892
|
+
}
|
|
3893
|
+
case "enumeration": {
|
|
3894
|
+
if (Array.isArray(attrMeta.enumOptions) && !attrMeta.enumOptions.includes(String(value))) {
|
|
3895
|
+
return `Must be one of: ${attrMeta.enumOptions.join(", ")}`;
|
|
3896
|
+
}
|
|
3897
|
+
return null;
|
|
3898
|
+
}
|
|
3899
|
+
case "email": {
|
|
3900
|
+
const s = String(value).trim();
|
|
3901
|
+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s)) return "Invalid email";
|
|
3902
|
+
return null;
|
|
3903
|
+
}
|
|
3904
|
+
case "uid": {
|
|
3905
|
+
const s = String(value).trim();
|
|
3906
|
+
if (!/^[A-Za-z0-9\-_.~]*$/.test(s)) return "Invalid UID format";
|
|
3907
|
+
return null;
|
|
3908
|
+
}
|
|
3909
|
+
case "json":
|
|
3910
|
+
case "blocks": {
|
|
3911
|
+
if (typeof value === "string") {
|
|
3912
|
+
try {
|
|
3913
|
+
const parsed = JSON.parse(value);
|
|
3914
|
+
if (type === "blocks" && parsed !== null && !Array.isArray(parsed)) {
|
|
3915
|
+
return "Blocks must be a JSON array";
|
|
3916
|
+
}
|
|
3917
|
+
} catch (err) {
|
|
3918
|
+
return `Invalid JSON: ${err.message}`;
|
|
3919
|
+
}
|
|
3920
|
+
} else if (type === "blocks" && !Array.isArray(value)) {
|
|
3921
|
+
return "Blocks must be an array";
|
|
3922
|
+
}
|
|
3923
|
+
return null;
|
|
3924
|
+
}
|
|
3925
|
+
case "date":
|
|
3926
|
+
case "datetime": {
|
|
3927
|
+
const d = new Date(String(value).trim());
|
|
3928
|
+
if (isNaN(d.getTime())) return "Invalid date/datetime";
|
|
3929
|
+
return null;
|
|
3930
|
+
}
|
|
3931
|
+
case "time": {
|
|
3932
|
+
if (!/^\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?$/.test(String(value).trim())) {
|
|
3933
|
+
return "Invalid time (HH:mm or HH:mm:ss)";
|
|
3934
|
+
}
|
|
3935
|
+
return null;
|
|
3936
|
+
}
|
|
3937
|
+
default: {
|
|
3938
|
+
const str = typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
3939
|
+
if (typeof attrMeta.minLength === "number" && str.length < attrMeta.minLength) {
|
|
3940
|
+
return `Min length ${attrMeta.minLength}`;
|
|
3941
|
+
}
|
|
3942
|
+
if (typeof attrMeta.maxLength === "number" && str.length > attrMeta.maxLength) {
|
|
3943
|
+
return `Max length ${attrMeta.maxLength}`;
|
|
3944
|
+
}
|
|
3945
|
+
if (attrMeta.regex) {
|
|
3946
|
+
try {
|
|
3947
|
+
if (!new RegExp(attrMeta.regex).test(str)) return `Must match /${attrMeta.regex}/`;
|
|
3948
|
+
} catch {
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3951
|
+
return null;
|
|
3952
|
+
}
|
|
3953
|
+
}
|
|
3954
|
+
}
|
|
3955
|
+
function cleanRuleKey(str) {
|
|
3956
|
+
return (str || "").replace(/[-_]/g, "").toLowerCase().trim();
|
|
3957
|
+
}
|
|
3958
|
+
function matchesFieldRulePath(attrPath, targetField) {
|
|
3959
|
+
if (!attrPath || !targetField) return false;
|
|
3960
|
+
const cleanAttr = parseAttrPathClient(attrPath).cleanPath;
|
|
3961
|
+
const parts = cleanAttr.split(".").map(cleanRuleKey).filter(Boolean);
|
|
3962
|
+
const leaf = parts[parts.length - 1] || "";
|
|
3963
|
+
const targetClean = cleanRuleKey(targetField.replace(/^api::/i, ""));
|
|
3964
|
+
if (leaf === targetClean || cleanRuleKey(cleanAttr) === targetClean) return true;
|
|
3965
|
+
const tSegs = targetField.replace(/^api::/i, "").split(".").map(cleanRuleKey).filter(Boolean);
|
|
3966
|
+
if (tSegs.length === 1) return leaf === tSegs[0];
|
|
3967
|
+
return tSegs.every((t) => t === "*" || parts.includes(t));
|
|
3968
|
+
}
|
|
3969
|
+
function computeRecordQuotaUsage(entry, attrPath, excludeOccurrenceKey, recordEdits, colAttributes, attrMeta, validationRules) {
|
|
3970
|
+
const occs = enumerateClientOccurrences(entry, attrPath, colAttributes, attrMeta);
|
|
3971
|
+
const usageCounts = {};
|
|
3972
|
+
for (const occ of occs) {
|
|
3973
|
+
if (occ.occurrenceKey === excludeOccurrenceKey) continue;
|
|
3974
|
+
const edited = recordEdits?.occurrences?.[occ.occurrenceKey];
|
|
3975
|
+
const effectiveVal = edited ? edited.value : occ.value;
|
|
3976
|
+
if (effectiveVal !== void 0 && effectiveVal !== null && String(effectiveVal).trim() !== "") {
|
|
3977
|
+
const k = String(effectiveVal).toLowerCase().trim();
|
|
3978
|
+
usageCounts[k] = (usageCounts[k] || 0) + 1;
|
|
3979
|
+
}
|
|
3980
|
+
}
|
|
3981
|
+
const quotas = {};
|
|
3982
|
+
if (attrMeta?.options?.items) {
|
|
3983
|
+
for (const item of attrMeta.options.items) {
|
|
3984
|
+
if (typeof item.maxAllowed === "number" && item.maxAllowed > 0) {
|
|
3985
|
+
quotas[item.value.toLowerCase().trim()] = item.maxAllowed;
|
|
3986
|
+
}
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
if (attrMeta?.options?.quotas) {
|
|
3990
|
+
for (const [k, v] of Object.entries(attrMeta.options.quotas)) {
|
|
3991
|
+
if (typeof v === "number" && v > 0) quotas[k.toLowerCase().trim()] = v;
|
|
3992
|
+
}
|
|
3993
|
+
}
|
|
3994
|
+
for (const rule of validationRules || []) {
|
|
3995
|
+
if (!rule.enabled) continue;
|
|
3996
|
+
if (rule.targetField && !matchesFieldRulePath(attrPath, rule.targetField)) continue;
|
|
3997
|
+
for (const [k, v] of Object.entries(rule.quotas || {})) {
|
|
3998
|
+
if (typeof v === "number" && v > 0) quotas[k.toLowerCase().trim()] = v;
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
4001
|
+
return { usageCounts, quotas };
|
|
4002
|
+
}
|
|
4003
|
+
function serializeGridTargets(gridEdits, selectedEntries, collectionPages = {}, attrMeta) {
|
|
4004
|
+
const targets = [];
|
|
4005
|
+
let totalEditCount = 0;
|
|
4006
|
+
let hasValidationErrors = false;
|
|
4007
|
+
for (const [key, rec] of Object.entries(gridEdits)) {
|
|
4008
|
+
if (!selectedEntries[key]) continue;
|
|
4009
|
+
const occEntries = Object.values(rec.occurrences || {});
|
|
4010
|
+
if (occEntries.length === 0) continue;
|
|
4011
|
+
for (const occ of occEntries) {
|
|
4012
|
+
if (occ.validationError) {
|
|
4013
|
+
hasValidationErrors = true;
|
|
4014
|
+
}
|
|
4015
|
+
}
|
|
4016
|
+
const colPage = collectionPages[rec.uid];
|
|
4017
|
+
const cachedEntry = colPage?.entries?.find((e) => e.documentId === rec.documentId);
|
|
4018
|
+
const targetObj = {
|
|
4019
|
+
uid: rec.uid,
|
|
4020
|
+
documentId: rec.documentId,
|
|
4021
|
+
status: cachedEntry?.status ?? rec.status,
|
|
4022
|
+
publishedAt: cachedEntry?.publishedAt ?? rec.publishedAt,
|
|
4023
|
+
locale: cachedEntry?.locale ?? rec.locale
|
|
4024
|
+
};
|
|
4025
|
+
const isScalarOnly = occEntries.length === 1 && occEntries[0].occurrenceKey === "__scalar__" && !attrMeta?.rootType;
|
|
4026
|
+
if (isScalarOnly) {
|
|
4027
|
+
targetObj.overrideValue = occEntries[0].value;
|
|
4028
|
+
totalEditCount += 1;
|
|
4029
|
+
} else {
|
|
4030
|
+
targetObj.occurrenceUpdates = occEntries.map((occ) => ({
|
|
4031
|
+
occurrenceKey: occ.occurrenceKey,
|
|
4032
|
+
segments: occ.segments,
|
|
4033
|
+
dynamicZoneIndex: occ.segments?.[0]?.index,
|
|
4034
|
+
componentId: occ.segments?.find((s) => s.componentId !== void 0)?.componentId,
|
|
4035
|
+
componentUid: occ.segments?.find((s) => s.componentUid)?.componentUid,
|
|
4036
|
+
value: occ.value
|
|
4037
|
+
}));
|
|
4038
|
+
totalEditCount += occEntries.length;
|
|
4039
|
+
}
|
|
4040
|
+
targets.push(targetObj);
|
|
4041
|
+
}
|
|
4042
|
+
return { targets, totalEditCount, hasValidationErrors };
|
|
4043
|
+
}
|
|
4044
|
+
const DEFAULT_HEADING_ITEMS = [
|
|
4045
|
+
{ value: "h1", label: "H1 - Main Page Title", maxAllowed: 1 },
|
|
4046
|
+
{ value: "h2", label: "H2 - Primary Section Heading", maxAllowed: 3 },
|
|
4047
|
+
{ value: "h3", label: "H3 - Sub-section Heading", maxAllowed: null },
|
|
4048
|
+
{ value: "h4", label: "H4 - Component Title", maxAllowed: null },
|
|
4049
|
+
{ value: "h5", label: "H5 - Card / Item Heading", maxAllowed: null },
|
|
4050
|
+
{ value: "h6", label: "H6 - Minor Heading", maxAllowed: null }
|
|
4051
|
+
];
|
|
4052
|
+
function toTextInputString(val, type) {
|
|
4053
|
+
if (val === null || val === void 0) return "";
|
|
4054
|
+
if (type === "date" && typeof val === "string") {
|
|
4055
|
+
return val.slice(0, 10);
|
|
4056
|
+
}
|
|
4057
|
+
if (type === "datetime" && typeof val === "string") {
|
|
4058
|
+
const d = new Date(val);
|
|
4059
|
+
if (!isNaN(d.getTime())) {
|
|
4060
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
4061
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
4062
|
+
}
|
|
4063
|
+
return val.slice(0, 16);
|
|
4064
|
+
}
|
|
4065
|
+
if (type === "time" && typeof val === "string") {
|
|
4066
|
+
return val.slice(0, 8);
|
|
4067
|
+
}
|
|
4068
|
+
if (typeof val === "object") {
|
|
4069
|
+
try {
|
|
4070
|
+
return JSON.stringify(val);
|
|
4071
|
+
} catch {
|
|
4072
|
+
return String(val);
|
|
4073
|
+
}
|
|
4074
|
+
}
|
|
4075
|
+
return String(val);
|
|
4076
|
+
}
|
|
4077
|
+
const GridCellEditor = React__default.memo(
|
|
4078
|
+
({
|
|
4079
|
+
entry,
|
|
4080
|
+
attribute,
|
|
4081
|
+
occurrence,
|
|
4082
|
+
attrMeta,
|
|
4083
|
+
editedValue,
|
|
4084
|
+
isDirty,
|
|
4085
|
+
validationError,
|
|
4086
|
+
relationOptions = [],
|
|
4087
|
+
relationOptionsLoading = false,
|
|
4088
|
+
relationIsMulti = false,
|
|
4089
|
+
validationRules = [],
|
|
4090
|
+
recordEdits,
|
|
4091
|
+
colAttributes,
|
|
4092
|
+
compact = false,
|
|
4093
|
+
onCommit,
|
|
4094
|
+
onReset
|
|
4095
|
+
}) => {
|
|
4096
|
+
const { get } = useFetchClient();
|
|
4097
|
+
const fieldType = String(attrMeta?.type || "").toLowerCase();
|
|
4098
|
+
const isScopedSelect = attrMeta?.customField === "plugin::bulk-updater.scoped-select" || attrMeta?.customField === "global::scoped-select";
|
|
4099
|
+
const isRelation = Boolean(attrMeta?.isRelation || fieldType === "relation");
|
|
4100
|
+
const isMultiRelation = isRelation && Boolean(relationIsMulti || ["oneToMany", "manyToMany"].includes(attrMeta?.relationType || ""));
|
|
4101
|
+
const effectiveValue = isDirty ? editedValue : occurrence.value;
|
|
4102
|
+
const [localText, setLocalText] = useState(() => toTextInputString(effectiveValue, fieldType));
|
|
4103
|
+
const [showRichModal, setShowRichModal] = useState(false);
|
|
4104
|
+
const [richDraft, setRichDraft] = useState("");
|
|
4105
|
+
const [richError, setRichError] = useState(null);
|
|
4106
|
+
const [showMultiRelModal, setShowMultiRelModal] = useState(false);
|
|
4107
|
+
const [multiRelSelected, setMultiRelSelected] = useState([]);
|
|
4108
|
+
const [multiRelMode, setMultiRelMode] = useState("set");
|
|
4109
|
+
const [multiRelSearch, setMultiRelSearch] = useState("");
|
|
4110
|
+
const [showMediaModal, setShowMediaModal] = useState(false);
|
|
4111
|
+
const [mediaOptions, setMediaOptions] = useState([]);
|
|
4112
|
+
const [mediaSearch, setMediaSearch] = useState("");
|
|
4113
|
+
const [mediaLoading, setMediaLoading] = useState(false);
|
|
4114
|
+
const [selectedMediaIds, setSelectedMediaIds] = useState([]);
|
|
4115
|
+
useEffect(() => {
|
|
4116
|
+
setLocalText(toTextInputString(effectiveValue, fieldType));
|
|
4117
|
+
}, [effectiveValue, fieldType, occurrence.occurrenceKey]);
|
|
4118
|
+
const commitTypedValue = (rawVal) => {
|
|
4119
|
+
if (areClientValuesEqual(rawVal, occurrence.value)) {
|
|
4120
|
+
onReset(occurrence.occurrenceKey);
|
|
4121
|
+
return;
|
|
4122
|
+
}
|
|
4123
|
+
const err = validateClientFieldValue(rawVal, attrMeta);
|
|
4124
|
+
onCommit(occurrence, rawVal, err);
|
|
4125
|
+
};
|
|
4126
|
+
const loadMediaLibrary = async (query = "") => {
|
|
4127
|
+
try {
|
|
4128
|
+
setMediaLoading(true);
|
|
4129
|
+
const res = await get(`/bulk-updater/media-options?search=${encodeURIComponent(query)}`);
|
|
4130
|
+
if (res.data?.success && Array.isArray(res.data.options)) {
|
|
4131
|
+
setMediaOptions(res.data.options);
|
|
4132
|
+
}
|
|
4133
|
+
} catch {
|
|
4134
|
+
setMediaOptions([]);
|
|
4135
|
+
} finally {
|
|
4136
|
+
setMediaLoading(false);
|
|
4137
|
+
}
|
|
4138
|
+
};
|
|
4139
|
+
const quotaContext = useMemo(() => {
|
|
4140
|
+
if (!isScopedSelect) return null;
|
|
4141
|
+
return computeRecordQuotaUsage(
|
|
4142
|
+
entry,
|
|
4143
|
+
attribute,
|
|
4144
|
+
occurrence.occurrenceKey,
|
|
4145
|
+
recordEdits,
|
|
4146
|
+
colAttributes,
|
|
4147
|
+
attrMeta,
|
|
4148
|
+
validationRules
|
|
4149
|
+
);
|
|
4150
|
+
}, [isScopedSelect, entry, attribute, occurrence.occurrenceKey, recordEdits, colAttributes, attrMeta, validationRules]);
|
|
4151
|
+
const scopedItems = useMemo(() => {
|
|
4152
|
+
if (!isScopedSelect) return [];
|
|
4153
|
+
const base = attrMeta?.options?.items && attrMeta.options.items.length > 0 ? attrMeta.options.items : DEFAULT_HEADING_ITEMS;
|
|
4154
|
+
const quotas = quotaContext?.quotas || {};
|
|
4155
|
+
return base.map((it) => {
|
|
4156
|
+
const key = it.value.toLowerCase().trim();
|
|
4157
|
+
const maxAllowed = typeof quotas[key] === "number" ? quotas[key] : it.maxAllowed;
|
|
4158
|
+
const usedBySiblings = quotaContext?.usageCounts?.[key] || 0;
|
|
4159
|
+
return {
|
|
4160
|
+
...it,
|
|
4161
|
+
maxAllowed,
|
|
4162
|
+
usedBySiblings,
|
|
4163
|
+
atLimit: typeof maxAllowed === "number" && maxAllowed > 0 && usedBySiblings >= maxAllowed
|
|
4164
|
+
};
|
|
4165
|
+
});
|
|
4166
|
+
}, [isScopedSelect, attrMeta, quotaContext]);
|
|
4167
|
+
const wrapperStyle = {
|
|
4168
|
+
borderLeft: isDirty ? "3px solid #4945ff" : "3px solid transparent",
|
|
4169
|
+
paddingLeft: 6,
|
|
4170
|
+
backgroundColor: validationError ? "rgba(208, 43, 32, 0.06)" : isDirty ? "rgba(73, 69, 255, 0.05)" : "transparent",
|
|
4171
|
+
borderRadius: 4,
|
|
4172
|
+
minWidth: compact ? 180 : 210,
|
|
4173
|
+
maxWidth: 320
|
|
4174
|
+
};
|
|
4175
|
+
const renderResetBtn = () => isDirty ? /* @__PURE__ */ jsx(
|
|
4176
|
+
Button,
|
|
4177
|
+
{
|
|
4178
|
+
variant: "ghost",
|
|
4179
|
+
size: "S",
|
|
4180
|
+
onClick: () => onReset(occurrence.occurrenceKey),
|
|
4181
|
+
title: "Revert this cell back to original database value",
|
|
4182
|
+
style: { padding: "4px 6px", minWidth: 28, height: 28 },
|
|
4183
|
+
children: /* @__PURE__ */ jsx(ArrowClockwise, {})
|
|
4184
|
+
}
|
|
4185
|
+
) : null;
|
|
4186
|
+
if (isScopedSelect) {
|
|
4187
|
+
const currentValStr = effectiveValue !== null && effectiveValue !== void 0 ? String(effectiveValue) : "__clear__";
|
|
4188
|
+
return /* @__PURE__ */ jsxs(Box, { style: wrapperStyle, children: [
|
|
4189
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", children: [
|
|
4190
|
+
/* @__PURE__ */ jsx(Box, { style: { flex: 1, minWidth: 145 }, children: /* @__PURE__ */ jsxs(
|
|
4191
|
+
SingleSelect,
|
|
4192
|
+
{
|
|
4193
|
+
size: "S",
|
|
4194
|
+
"aria-label": `Edit ${occurrence.displayPath}`,
|
|
4195
|
+
value: currentValStr,
|
|
4196
|
+
onChange: (val) => {
|
|
4197
|
+
const s = String(val);
|
|
4198
|
+
commitTypedValue(s === "__clear__" ? null : s);
|
|
4199
|
+
},
|
|
4200
|
+
children: [
|
|
4201
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "__clear__", children: "-- Unset --" }),
|
|
4202
|
+
scopedItems.map((it) => {
|
|
4203
|
+
const isCurrentlySelected = currentValStr.toLowerCase() === it.value.toLowerCase();
|
|
4204
|
+
const quotaNote = typeof it.maxAllowed === "number" && it.maxAllowed > 0 ? ` (${it.usedBySiblings + (isCurrentlySelected ? 1 : 0)}/${it.maxAllowed})` : "";
|
|
4205
|
+
return /* @__PURE__ */ jsxs(SingleSelectOption, { value: it.value, children: [
|
|
4206
|
+
it.label,
|
|
4207
|
+
quotaNote,
|
|
4208
|
+
it.atLimit && !isCurrentlySelected ? " [QUOTA FULL]" : ""
|
|
4209
|
+
] }, it.value);
|
|
4210
|
+
})
|
|
4211
|
+
]
|
|
4212
|
+
}
|
|
4213
|
+
) }),
|
|
4214
|
+
renderResetBtn()
|
|
4215
|
+
] }),
|
|
4216
|
+
validationError && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger700", display: "block", style: { fontSize: "0.7rem", marginTop: 2 }, children: validationError })
|
|
4217
|
+
] });
|
|
4218
|
+
}
|
|
4219
|
+
if (fieldType === "enumeration" && Array.isArray(attrMeta?.enumOptions)) {
|
|
4220
|
+
const currentValStr = effectiveValue !== null && effectiveValue !== void 0 && effectiveValue !== "" ? String(effectiveValue) : "__clear__";
|
|
4221
|
+
return /* @__PURE__ */ jsxs(Box, { style: wrapperStyle, children: [
|
|
4222
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", children: [
|
|
4223
|
+
/* @__PURE__ */ jsx(Box, { style: { flex: 1, minWidth: 145 }, children: /* @__PURE__ */ jsxs(
|
|
4224
|
+
SingleSelect,
|
|
4225
|
+
{
|
|
4226
|
+
size: "S",
|
|
4227
|
+
"aria-label": `Edit ${occurrence.displayPath}`,
|
|
4228
|
+
value: currentValStr,
|
|
4229
|
+
onChange: (val) => {
|
|
4230
|
+
const s = String(val);
|
|
4231
|
+
commitTypedValue(s === "__clear__" ? null : s);
|
|
4232
|
+
},
|
|
4233
|
+
children: [
|
|
4234
|
+
!attrMeta.required && /* @__PURE__ */ jsx(SingleSelectOption, { value: "__clear__", children: "-- Clear (null) --" }),
|
|
4235
|
+
attrMeta.enumOptions.map((opt) => /* @__PURE__ */ jsx(SingleSelectOption, { value: opt, children: opt }, opt))
|
|
4236
|
+
]
|
|
4237
|
+
}
|
|
4238
|
+
) }),
|
|
4239
|
+
renderResetBtn()
|
|
4240
|
+
] }),
|
|
4241
|
+
validationError && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger700", display: "block", style: { fontSize: "0.7rem" }, children: validationError })
|
|
4242
|
+
] });
|
|
4243
|
+
}
|
|
4244
|
+
if (fieldType === "boolean") {
|
|
4245
|
+
const strVal = effectiveValue === true ? "true" : effectiveValue === false ? "false" : "__unset__";
|
|
4246
|
+
return /* @__PURE__ */ jsxs(Box, { style: wrapperStyle, children: [
|
|
4247
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", children: [
|
|
4248
|
+
/* @__PURE__ */ jsx(Box, { style: { flex: 1, minWidth: 120 }, children: /* @__PURE__ */ jsxs(
|
|
4249
|
+
SingleSelect,
|
|
4250
|
+
{
|
|
4251
|
+
size: "S",
|
|
4252
|
+
"aria-label": `Edit ${occurrence.displayPath}`,
|
|
4253
|
+
value: strVal,
|
|
4254
|
+
onChange: (val) => {
|
|
4255
|
+
const s = String(val);
|
|
4256
|
+
commitTypedValue(s === "true" ? true : s === "false" ? false : null);
|
|
4257
|
+
},
|
|
4258
|
+
children: [
|
|
4259
|
+
!attrMeta?.required && /* @__PURE__ */ jsx(SingleSelectOption, { value: "__unset__", children: "-- Unset --" }),
|
|
4260
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "true", children: "true" }),
|
|
4261
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "false", children: "false" })
|
|
4262
|
+
]
|
|
4263
|
+
}
|
|
4264
|
+
) }),
|
|
4265
|
+
renderResetBtn()
|
|
4266
|
+
] }),
|
|
4267
|
+
validationError && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger700", display: "block", style: { fontSize: "0.7rem" }, children: validationError })
|
|
4268
|
+
] });
|
|
4269
|
+
}
|
|
4270
|
+
if (isRelation) {
|
|
4271
|
+
const cmd = extractRelationEditCommand(effectiveValue, occurrence.value, isMultiRelation);
|
|
4272
|
+
if (!isMultiRelation) {
|
|
4273
|
+
const selectedDocId = cmd.mode === "clear" ? "__clear__" : cmd.documentIds[0] || "__clear__";
|
|
4274
|
+
return /* @__PURE__ */ jsxs(Box, { style: wrapperStyle, children: [
|
|
4275
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", children: [
|
|
4276
|
+
/* @__PURE__ */ jsx(Box, { style: { flex: 1, minWidth: 165 }, children: /* @__PURE__ */ jsxs(
|
|
4277
|
+
Combobox,
|
|
4278
|
+
{
|
|
4279
|
+
autocomplete: { type: "list", filter: "contains" },
|
|
4280
|
+
placeholder: relationOptionsLoading ? "Loading..." : "Pick relation...",
|
|
4281
|
+
value: selectedDocId,
|
|
4282
|
+
onChange: (val) => {
|
|
4283
|
+
const docId = val ? String(val) : "__clear__";
|
|
4284
|
+
if (docId === "__clear__") {
|
|
4285
|
+
commitTypedValue({ mode: "clear", documentIds: [], label: "(cleared / unlinked)" });
|
|
4286
|
+
} else {
|
|
4287
|
+
const opt = relationOptions.find((o) => o.documentId === docId);
|
|
4288
|
+
commitTypedValue({ mode: "set", documentIds: [docId], label: opt?.label || docId });
|
|
4289
|
+
}
|
|
4290
|
+
},
|
|
4291
|
+
children: [
|
|
4292
|
+
/* @__PURE__ */ jsx(ComboboxOption, { value: "__clear__", textValue: "Clear / Unlink Relation", children: "-- Clear / Unlink --" }),
|
|
4293
|
+
relationOptions.map((opt) => /* @__PURE__ */ jsx(ComboboxOption, { value: opt.documentId, textValue: opt.label, children: opt.label }, opt.documentId))
|
|
4294
|
+
]
|
|
4295
|
+
}
|
|
4296
|
+
) }),
|
|
4297
|
+
renderResetBtn()
|
|
4298
|
+
] }),
|
|
4299
|
+
validationError && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger700", display: "block", style: { fontSize: "0.7rem" }, children: validationError })
|
|
4300
|
+
] });
|
|
4301
|
+
}
|
|
4302
|
+
const displaySummary = cmd.mode === "clear" ? "(cleared / empty)" : cmd.label || (cmd.documentIds.length > 0 ? `${cmd.documentIds.length} linked (${cmd.mode})` : "(unlinked)");
|
|
4303
|
+
const filteredRelOpts = relationOptions.filter(
|
|
4304
|
+
(o) => !multiRelSearch.trim() || o.label.toLowerCase().includes(multiRelSearch.toLowerCase())
|
|
4305
|
+
);
|
|
4306
|
+
return /* @__PURE__ */ jsxs(Box, { style: wrapperStyle, children: [
|
|
4307
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", children: [
|
|
4308
|
+
/* @__PURE__ */ jsx(
|
|
4309
|
+
Button,
|
|
4310
|
+
{
|
|
4311
|
+
variant: "tertiary",
|
|
4312
|
+
size: "S",
|
|
4313
|
+
onClick: () => {
|
|
4314
|
+
setMultiRelSelected(cmd.documentIds || []);
|
|
4315
|
+
setMultiRelMode(cmd.mode === "clear" && (cmd.documentIds || []).length === 0 ? "set" : cmd.mode);
|
|
4316
|
+
setMultiRelSearch("");
|
|
4317
|
+
setShowMultiRelModal(true);
|
|
4318
|
+
},
|
|
4319
|
+
style: { maxWidth: 230, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
|
|
4320
|
+
children: displaySummary
|
|
4321
|
+
}
|
|
4322
|
+
),
|
|
4323
|
+
renderResetBtn()
|
|
4324
|
+
] }),
|
|
4325
|
+
showMultiRelModal && /* @__PURE__ */ jsx(
|
|
4326
|
+
"div",
|
|
4327
|
+
{
|
|
4328
|
+
style: {
|
|
4329
|
+
position: "fixed",
|
|
4330
|
+
inset: 0,
|
|
4331
|
+
backgroundColor: "rgba(20, 20, 30, 0.55)",
|
|
4332
|
+
zIndex: 9999,
|
|
4333
|
+
display: "flex",
|
|
4334
|
+
alignItems: "center",
|
|
4335
|
+
justifyContent: "center",
|
|
4336
|
+
padding: 16
|
|
4337
|
+
},
|
|
4338
|
+
onClick: () => setShowMultiRelModal(false),
|
|
4339
|
+
children: /* @__PURE__ */ jsxs(
|
|
4340
|
+
Box,
|
|
4341
|
+
{
|
|
4342
|
+
padding: 5,
|
|
4343
|
+
background: "neutral0",
|
|
4344
|
+
hasRadius: true,
|
|
4345
|
+
shadow: "popupShadow",
|
|
4346
|
+
style: { width: "92%", maxWidth: 520, maxHeight: "80vh", display: "flex", flexDirection: "column" },
|
|
4347
|
+
onClick: (e) => e.stopPropagation(),
|
|
4348
|
+
children: [
|
|
4349
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "delta", fontWeight: "bold", marginBottom: 2, children: [
|
|
4350
|
+
"Edit Multi-Relation: ",
|
|
4351
|
+
occurrence.displayPath
|
|
4352
|
+
] }),
|
|
4353
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, marginBottom: 3, alignItems: "center", children: [
|
|
4354
|
+
/* @__PURE__ */ jsx(Box, { style: { width: 180 }, children: /* @__PURE__ */ jsxs(
|
|
4355
|
+
SingleSelect,
|
|
4356
|
+
{
|
|
4357
|
+
label: "Operation",
|
|
4358
|
+
value: multiRelMode,
|
|
4359
|
+
onChange: (v) => setMultiRelMode(String(v)),
|
|
4360
|
+
children: [
|
|
4361
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "set", children: "Set / Replace All" }),
|
|
4362
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "connect", children: "Add / Connect" }),
|
|
4363
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "disconnect", children: "Remove / Disconnect" }),
|
|
4364
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "clear", children: "Clear All" })
|
|
4365
|
+
]
|
|
4366
|
+
}
|
|
4367
|
+
) }),
|
|
4368
|
+
/* @__PURE__ */ jsx(Box, { style: { flex: 1 }, children: /* @__PURE__ */ jsx(
|
|
4369
|
+
TextInput,
|
|
4370
|
+
{
|
|
4371
|
+
label: "Filter items",
|
|
4372
|
+
placeholder: "Search relations...",
|
|
4373
|
+
value: multiRelSearch,
|
|
4374
|
+
onChange: (e) => setMultiRelSearch(e.target.value)
|
|
4375
|
+
}
|
|
4376
|
+
) })
|
|
4377
|
+
] }),
|
|
4378
|
+
multiRelMode !== "clear" && /* @__PURE__ */ jsx(
|
|
4379
|
+
Box,
|
|
4380
|
+
{
|
|
4381
|
+
padding: 2,
|
|
4382
|
+
hasRadius: true,
|
|
4383
|
+
style: { border: "1px solid #eaeaef", overflowY: "auto", maxHeight: 280, marginBottom: 16 },
|
|
4384
|
+
children: filteredRelOpts.length === 0 ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: "No target entities found." }) : filteredRelOpts.map((opt) => {
|
|
4385
|
+
const checked = multiRelSelected.includes(opt.documentId);
|
|
4386
|
+
return /* @__PURE__ */ jsx(Box, { padding: 1, children: /* @__PURE__ */ jsx(
|
|
4387
|
+
Checkbox,
|
|
4388
|
+
{
|
|
4389
|
+
checked,
|
|
4390
|
+
onCheckedChange: (isChecked) => {
|
|
4391
|
+
setMultiRelSelected(
|
|
4392
|
+
(prev) => isChecked ? [...prev, opt.documentId] : prev.filter((id) => id !== opt.documentId)
|
|
4393
|
+
);
|
|
4394
|
+
},
|
|
4395
|
+
children: /* @__PURE__ */ jsx(Typography, { variant: "omega", children: opt.label })
|
|
4396
|
+
}
|
|
4397
|
+
) }, opt.documentId);
|
|
4398
|
+
})
|
|
4399
|
+
}
|
|
4400
|
+
),
|
|
4401
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "flex-end", gap: 2, children: [
|
|
4402
|
+
/* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: () => setShowMultiRelModal(false), children: "Cancel" }),
|
|
4403
|
+
/* @__PURE__ */ jsx(
|
|
4404
|
+
Button,
|
|
4405
|
+
{
|
|
4406
|
+
variant: "default",
|
|
4407
|
+
startIcon: /* @__PURE__ */ jsx(Check, {}),
|
|
4408
|
+
onClick: () => {
|
|
4409
|
+
if (multiRelMode === "clear") {
|
|
4410
|
+
commitTypedValue({ mode: "clear", documentIds: [], label: "(cleared / unlinked)" });
|
|
4411
|
+
} else {
|
|
4412
|
+
const labels = relationOptions.filter((o) => multiRelSelected.includes(o.documentId)).map((o) => o.label).join(", ");
|
|
4413
|
+
commitTypedValue({
|
|
4414
|
+
mode: multiRelMode,
|
|
4415
|
+
documentIds: multiRelSelected,
|
|
4416
|
+
label: labels || `${multiRelSelected.length} selected`
|
|
4417
|
+
});
|
|
4418
|
+
}
|
|
4419
|
+
setShowMultiRelModal(false);
|
|
4420
|
+
},
|
|
4421
|
+
children: "Apply Relation Edit"
|
|
4422
|
+
}
|
|
4423
|
+
)
|
|
4424
|
+
] })
|
|
4425
|
+
]
|
|
4426
|
+
}
|
|
4427
|
+
)
|
|
4428
|
+
}
|
|
4429
|
+
)
|
|
4430
|
+
] });
|
|
4431
|
+
}
|
|
4432
|
+
if (fieldType === "media") {
|
|
4433
|
+
const isMultiMedia = Boolean(attrMeta?.multiple);
|
|
4434
|
+
const currentIds = Array.isArray(effectiveValue) ? effectiveValue.map((v) => typeof v === "object" ? Number(v?.id) : Number(v)).filter((n) => !isNaN(n)) : typeof effectiveValue === "object" && effectiveValue?.id ? [Number(effectiveValue.id)] : typeof effectiveValue === "number" ? [effectiveValue] : [];
|
|
4435
|
+
const mediaSummary = currentIds.length === 0 ? "(no media — pick)" : Array.isArray(effectiveValue) ? `${currentIds.length} asset(s)` : effectiveValue?.name ? `${effectiveValue.name} (#${currentIds[0]})` : `Media #${currentIds[0]}`;
|
|
4436
|
+
return /* @__PURE__ */ jsxs(Box, { style: wrapperStyle, children: [
|
|
4437
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", children: [
|
|
4438
|
+
/* @__PURE__ */ jsx(
|
|
4439
|
+
Button,
|
|
4440
|
+
{
|
|
4441
|
+
variant: "tertiary",
|
|
4442
|
+
size: "S",
|
|
4443
|
+
onClick: () => {
|
|
4444
|
+
setSelectedMediaIds(currentIds);
|
|
4445
|
+
setMediaSearch("");
|
|
4446
|
+
setShowMediaModal(true);
|
|
4447
|
+
loadMediaLibrary("");
|
|
4448
|
+
},
|
|
4449
|
+
style: { maxWidth: 220, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
|
|
4450
|
+
children: mediaSummary
|
|
4451
|
+
}
|
|
4452
|
+
),
|
|
4453
|
+
renderResetBtn()
|
|
4454
|
+
] }),
|
|
4455
|
+
showMediaModal && /* @__PURE__ */ jsx(
|
|
4456
|
+
"div",
|
|
4457
|
+
{
|
|
4458
|
+
style: {
|
|
4459
|
+
position: "fixed",
|
|
4460
|
+
inset: 0,
|
|
4461
|
+
backgroundColor: "rgba(20, 20, 30, 0.55)",
|
|
4462
|
+
zIndex: 9999,
|
|
4463
|
+
display: "flex",
|
|
4464
|
+
alignItems: "center",
|
|
4465
|
+
justifyContent: "center",
|
|
4466
|
+
padding: 16
|
|
4467
|
+
},
|
|
4468
|
+
onClick: () => setShowMediaModal(false),
|
|
4469
|
+
children: /* @__PURE__ */ jsxs(
|
|
4470
|
+
Box,
|
|
4471
|
+
{
|
|
4472
|
+
padding: 5,
|
|
4473
|
+
background: "neutral0",
|
|
4474
|
+
hasRadius: true,
|
|
4475
|
+
shadow: "popupShadow",
|
|
4476
|
+
style: { width: "92%", maxWidth: 620, maxHeight: "82vh", display: "flex", flexDirection: "column" },
|
|
4477
|
+
onClick: (e) => e.stopPropagation(),
|
|
4478
|
+
children: [
|
|
4479
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "delta", fontWeight: "bold", marginBottom: 3, children: [
|
|
4480
|
+
"Select Media Asset",
|
|
4481
|
+
isMultiMedia ? "s" : "",
|
|
4482
|
+
": ",
|
|
4483
|
+
occurrence.displayPath
|
|
4484
|
+
] }),
|
|
4485
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, marginBottom: 3, children: [
|
|
4486
|
+
/* @__PURE__ */ jsx(Box, { style: { flex: 1 }, children: /* @__PURE__ */ jsx(
|
|
4487
|
+
TextInput,
|
|
4488
|
+
{
|
|
4489
|
+
placeholder: "Search media filename or MIME...",
|
|
4490
|
+
value: mediaSearch,
|
|
4491
|
+
onChange: (e) => setMediaSearch(e.target.value)
|
|
4492
|
+
}
|
|
4493
|
+
) }),
|
|
4494
|
+
/* @__PURE__ */ jsx(
|
|
4495
|
+
Button,
|
|
4496
|
+
{
|
|
4497
|
+
variant: "secondary",
|
|
4498
|
+
startIcon: /* @__PURE__ */ jsx(Search, {}),
|
|
4499
|
+
onClick: () => loadMediaLibrary(mediaSearch),
|
|
4500
|
+
loading: mediaLoading,
|
|
4501
|
+
children: "Search"
|
|
4502
|
+
}
|
|
4503
|
+
)
|
|
4504
|
+
] }),
|
|
4505
|
+
/* @__PURE__ */ jsx(
|
|
4506
|
+
Box,
|
|
4507
|
+
{
|
|
4508
|
+
padding: 2,
|
|
4509
|
+
hasRadius: true,
|
|
4510
|
+
style: { border: "1px solid #eaeaef", overflowY: "auto", maxHeight: 320, marginBottom: 16 },
|
|
4511
|
+
children: mediaLoading ? /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Loader, { small: true, children: "Loading Media Library..." }) }) : mediaOptions.length === 0 ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: "No media files matched." }) : mediaOptions.map((file) => {
|
|
4512
|
+
const isChecked = selectedMediaIds.includes(file.id);
|
|
4513
|
+
return /* @__PURE__ */ jsx(Box, { padding: 2, style: { borderBottom: "1px solid #f0f0f5" }, children: /* @__PURE__ */ jsx(
|
|
4514
|
+
Checkbox,
|
|
4515
|
+
{
|
|
4516
|
+
checked: isChecked,
|
|
4517
|
+
onCheckedChange: (checked) => {
|
|
4518
|
+
if (isMultiMedia) {
|
|
4519
|
+
setSelectedMediaIds(
|
|
4520
|
+
(prev) => checked ? [...prev, file.id] : prev.filter((id) => id !== file.id)
|
|
4521
|
+
);
|
|
4522
|
+
} else {
|
|
4523
|
+
setSelectedMediaIds(checked ? [file.id] : []);
|
|
4524
|
+
}
|
|
4525
|
+
},
|
|
4526
|
+
children: /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
|
|
4527
|
+
/* @__PURE__ */ jsxs(Badge, { backgroundColor: "neutral150", textColor: "neutral700", size: "S", children: [
|
|
4528
|
+
"#",
|
|
4529
|
+
file.id
|
|
4530
|
+
] }),
|
|
4531
|
+
/* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: file.name }),
|
|
4532
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral500", children: [
|
|
4533
|
+
"(",
|
|
4534
|
+
file.mime,
|
|
4535
|
+
")"
|
|
4536
|
+
] })
|
|
4537
|
+
] })
|
|
4538
|
+
}
|
|
4539
|
+
) }, file.id);
|
|
4540
|
+
})
|
|
4541
|
+
}
|
|
4542
|
+
),
|
|
4543
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", gap: 2, children: [
|
|
4544
|
+
/* @__PURE__ */ jsx(
|
|
4545
|
+
Button,
|
|
4546
|
+
{
|
|
4547
|
+
variant: "danger-light",
|
|
4548
|
+
onClick: () => {
|
|
4549
|
+
commitTypedValue(isMultiMedia ? [] : null);
|
|
4550
|
+
setShowMediaModal(false);
|
|
4551
|
+
},
|
|
4552
|
+
children: "Clear Media"
|
|
4553
|
+
}
|
|
4554
|
+
),
|
|
4555
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
|
4556
|
+
/* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: () => setShowMediaModal(false), children: "Cancel" }),
|
|
4557
|
+
/* @__PURE__ */ jsx(
|
|
4558
|
+
Button,
|
|
4559
|
+
{
|
|
4560
|
+
variant: "default",
|
|
4561
|
+
startIcon: /* @__PURE__ */ jsx(Check, {}),
|
|
4562
|
+
onClick: () => {
|
|
4563
|
+
commitTypedValue(isMultiMedia ? selectedMediaIds : selectedMediaIds[0] ?? null);
|
|
4564
|
+
setShowMediaModal(false);
|
|
4565
|
+
},
|
|
4566
|
+
children: "Apply Selection"
|
|
4567
|
+
}
|
|
4568
|
+
)
|
|
4569
|
+
] })
|
|
4570
|
+
] })
|
|
4571
|
+
]
|
|
4572
|
+
}
|
|
4573
|
+
)
|
|
4574
|
+
}
|
|
4575
|
+
)
|
|
4576
|
+
] });
|
|
4577
|
+
}
|
|
4578
|
+
if (fieldType === "richtext" || fieldType === "blocks" || fieldType === "json") {
|
|
4579
|
+
const isJsonOrBlocks = fieldType === "blocks" || fieldType === "json";
|
|
4580
|
+
const displayLabel = effectiveValue === null || effectiveValue === void 0 || effectiveValue === "" ? "(empty — edit)" : typeof effectiveValue === "object" ? JSON.stringify(effectiveValue).slice(0, 32) + (JSON.stringify(effectiveValue).length > 32 ? "…" : "") : String(effectiveValue).slice(0, 32) + (String(effectiveValue).length > 32 ? "…" : "");
|
|
4581
|
+
return /* @__PURE__ */ jsxs(Box, { style: wrapperStyle, children: [
|
|
4582
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", children: [
|
|
4583
|
+
/* @__PURE__ */ jsx(
|
|
4584
|
+
Button,
|
|
4585
|
+
{
|
|
4586
|
+
variant: "tertiary",
|
|
4587
|
+
size: "S",
|
|
4588
|
+
onClick: () => {
|
|
4589
|
+
const formatted = effectiveValue === null || effectiveValue === void 0 ? "" : typeof effectiveValue === "object" ? JSON.stringify(effectiveValue, null, 2) : String(effectiveValue);
|
|
4590
|
+
setRichDraft(formatted);
|
|
4591
|
+
setRichError(null);
|
|
4592
|
+
setShowRichModal(true);
|
|
4593
|
+
},
|
|
4594
|
+
style: { maxWidth: 230, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
|
|
4595
|
+
children: displayLabel
|
|
4596
|
+
}
|
|
4597
|
+
),
|
|
4598
|
+
renderResetBtn()
|
|
4599
|
+
] }),
|
|
4600
|
+
validationError && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger700", display: "block", style: { fontSize: "0.7rem" }, children: validationError }),
|
|
4601
|
+
showRichModal && /* @__PURE__ */ jsx(
|
|
4602
|
+
"div",
|
|
4603
|
+
{
|
|
4604
|
+
style: {
|
|
4605
|
+
position: "fixed",
|
|
4606
|
+
inset: 0,
|
|
4607
|
+
backgroundColor: "rgba(20, 20, 30, 0.55)",
|
|
4608
|
+
zIndex: 9999,
|
|
4609
|
+
display: "flex",
|
|
4610
|
+
alignItems: "center",
|
|
4611
|
+
justifyContent: "center",
|
|
4612
|
+
padding: 16
|
|
4613
|
+
},
|
|
4614
|
+
onClick: () => setShowRichModal(false),
|
|
4615
|
+
children: /* @__PURE__ */ jsxs(
|
|
4616
|
+
Box,
|
|
4617
|
+
{
|
|
4618
|
+
padding: 5,
|
|
4619
|
+
background: "neutral0",
|
|
4620
|
+
hasRadius: true,
|
|
4621
|
+
shadow: "popupShadow",
|
|
4622
|
+
style: { width: "92%", maxWidth: 640, display: "flex", flexDirection: "column", gap: 12 },
|
|
4623
|
+
onClick: (e) => e.stopPropagation(),
|
|
4624
|
+
children: [
|
|
4625
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "delta", fontWeight: "bold", children: [
|
|
4626
|
+
"Edit ",
|
|
4627
|
+
fieldType.toUpperCase(),
|
|
4628
|
+
": ",
|
|
4629
|
+
occurrence.displayPath
|
|
4630
|
+
] }),
|
|
4631
|
+
/* @__PURE__ */ jsx(
|
|
4632
|
+
Textarea,
|
|
4633
|
+
{
|
|
4634
|
+
name: "richDraft",
|
|
4635
|
+
"aria-label": "Rich content editor",
|
|
4636
|
+
value: richDraft,
|
|
4637
|
+
onChange: (e) => {
|
|
4638
|
+
setRichDraft(e.target.value);
|
|
4639
|
+
if (isJsonOrBlocks && e.target.value.trim()) {
|
|
4640
|
+
try {
|
|
4641
|
+
const parsed = JSON.parse(e.target.value);
|
|
4642
|
+
if (fieldType === "blocks" && !Array.isArray(parsed)) {
|
|
4643
|
+
setRichError("Strapi Blocks value must be a JSON array.");
|
|
4644
|
+
} else {
|
|
4645
|
+
setRichError(null);
|
|
4646
|
+
}
|
|
4647
|
+
} catch (err) {
|
|
4648
|
+
setRichError(`Invalid JSON: ${err.message}`);
|
|
4649
|
+
}
|
|
4650
|
+
} else {
|
|
4651
|
+
setRichError(null);
|
|
4652
|
+
}
|
|
4653
|
+
},
|
|
4654
|
+
style: { minHeight: 220, fontFamily: isJsonOrBlocks ? "monospace" : "inherit" }
|
|
4655
|
+
}
|
|
4656
|
+
),
|
|
4657
|
+
richError && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger700", fontWeight: "bold", children: richError }),
|
|
4658
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", gap: 2, children: [
|
|
4659
|
+
/* @__PURE__ */ jsx(
|
|
4660
|
+
Button,
|
|
4661
|
+
{
|
|
4662
|
+
variant: "danger-light",
|
|
4663
|
+
onClick: () => {
|
|
4664
|
+
commitTypedValue(isJsonOrBlocks ? null : "");
|
|
4665
|
+
setShowRichModal(false);
|
|
4666
|
+
},
|
|
4667
|
+
children: "Clear Value"
|
|
4668
|
+
}
|
|
4669
|
+
),
|
|
4670
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
|
4671
|
+
/* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: () => setShowRichModal(false), children: "Cancel" }),
|
|
4672
|
+
/* @__PURE__ */ jsx(
|
|
4673
|
+
Button,
|
|
4674
|
+
{
|
|
4675
|
+
variant: "default",
|
|
4676
|
+
disabled: Boolean(richError),
|
|
4677
|
+
startIcon: /* @__PURE__ */ jsx(Check, {}),
|
|
4678
|
+
onClick: () => {
|
|
4679
|
+
if (isJsonOrBlocks) {
|
|
4680
|
+
if (!richDraft.trim()) {
|
|
4681
|
+
commitTypedValue(null);
|
|
4682
|
+
} else {
|
|
4683
|
+
commitTypedValue(JSON.parse(richDraft));
|
|
4684
|
+
}
|
|
4685
|
+
} else {
|
|
4686
|
+
commitTypedValue(richDraft);
|
|
4687
|
+
}
|
|
4688
|
+
setShowRichModal(false);
|
|
4689
|
+
},
|
|
4690
|
+
children: "Apply Edit"
|
|
4691
|
+
}
|
|
4692
|
+
)
|
|
4693
|
+
] })
|
|
4694
|
+
] })
|
|
4695
|
+
]
|
|
4696
|
+
}
|
|
4697
|
+
)
|
|
4698
|
+
}
|
|
4699
|
+
)
|
|
4700
|
+
] });
|
|
4701
|
+
}
|
|
4702
|
+
if (fieldType === "date" || fieldType === "time" || fieldType === "datetime") {
|
|
4703
|
+
const inputType = fieldType === "datetime" ? "datetime-local" : fieldType;
|
|
4704
|
+
return /* @__PURE__ */ jsxs(Box, { style: wrapperStyle, children: [
|
|
4705
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", children: [
|
|
4706
|
+
/* @__PURE__ */ jsx(
|
|
4707
|
+
"input",
|
|
4708
|
+
{
|
|
4709
|
+
type: inputType,
|
|
4710
|
+
"aria-label": `Edit ${occurrence.displayPath}`,
|
|
4711
|
+
value: localText,
|
|
4712
|
+
step: fieldType === "time" ? 1 : void 0,
|
|
4713
|
+
onChange: (e) => {
|
|
4714
|
+
const v = e.target.value;
|
|
4715
|
+
setLocalText(v);
|
|
4716
|
+
commitTypedValue(v === "" ? null : v);
|
|
4717
|
+
},
|
|
4718
|
+
style: {
|
|
4719
|
+
padding: "6px 8px",
|
|
4720
|
+
borderRadius: 4,
|
|
4721
|
+
border: "1px solid #dcdce4",
|
|
4722
|
+
fontSize: "0.85rem",
|
|
4723
|
+
minWidth: 165
|
|
4724
|
+
}
|
|
4725
|
+
}
|
|
4726
|
+
),
|
|
4727
|
+
renderResetBtn()
|
|
4728
|
+
] }),
|
|
4729
|
+
validationError && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger700", display: "block", style: { fontSize: "0.7rem" }, children: validationError })
|
|
4730
|
+
] });
|
|
4731
|
+
}
|
|
4732
|
+
const isNumeric = ["integer", "biginteger", "float", "decimal", "number"].includes(fieldType);
|
|
4733
|
+
const inputStep = fieldType === "integer" || fieldType === "biginteger" ? "1" : isNumeric ? "any" : void 0;
|
|
4734
|
+
return /* @__PURE__ */ jsxs(Box, { style: wrapperStyle, children: [
|
|
4735
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", children: [
|
|
4736
|
+
/* @__PURE__ */ jsx(Box, { style: { flex: 1, minWidth: 150 }, children: /* @__PURE__ */ jsx(
|
|
4737
|
+
TextInput,
|
|
4738
|
+
{
|
|
4739
|
+
size: "S",
|
|
4740
|
+
type: isNumeric && fieldType !== "biginteger" ? "number" : "text",
|
|
4741
|
+
step: inputStep,
|
|
4742
|
+
"aria-label": `Edit ${occurrence.displayPath}`,
|
|
4743
|
+
placeholder: occurrence.isMissingIntermediate ? "Click to initialize..." : "(empty)",
|
|
4744
|
+
value: localText,
|
|
4745
|
+
onChange: (e) => {
|
|
4746
|
+
const next = e.target.value;
|
|
4747
|
+
setLocalText(next);
|
|
4748
|
+
commitTypedValue(isNumeric && next === "" ? null : next);
|
|
4749
|
+
}
|
|
4750
|
+
}
|
|
4751
|
+
) }),
|
|
4752
|
+
renderResetBtn()
|
|
4753
|
+
] }),
|
|
4754
|
+
validationError && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger700", display: "block", style: { fontSize: "0.7rem", marginTop: 2 }, children: validationError })
|
|
4755
|
+
] });
|
|
4756
|
+
}
|
|
4757
|
+
);
|
|
4758
|
+
const ComponentOccurrencesDrawer = React__default.memo(
|
|
4759
|
+
({
|
|
4760
|
+
colUid,
|
|
4761
|
+
rootKey,
|
|
4762
|
+
entry,
|
|
4763
|
+
selectedAttribute,
|
|
4764
|
+
attrMeta,
|
|
4765
|
+
colAttributes,
|
|
4766
|
+
gridEditMode,
|
|
4767
|
+
isSelected,
|
|
4768
|
+
selectedDzBlocks,
|
|
4769
|
+
occurrences,
|
|
4770
|
+
recordEdits,
|
|
4771
|
+
relationOptions,
|
|
4772
|
+
relationOptionsLoading,
|
|
4773
|
+
relationIsMulti,
|
|
4774
|
+
validationRules,
|
|
4775
|
+
onToggleDzBlock,
|
|
4776
|
+
onCommitEdit,
|
|
4777
|
+
onResetEdit
|
|
4778
|
+
}) => {
|
|
4779
|
+
const cleanRootKey = rootKey || (selectedAttribute || "").split("[")[0].split(".")[0];
|
|
4780
|
+
const selectedRootKey = selectedAttribute ? selectedAttribute.split("[")[0].split(".")[0] : "";
|
|
4781
|
+
const targetsThisRoot = Boolean(selectedAttribute && selectedRootKey === cleanRootKey);
|
|
4782
|
+
const blocks = Array.isArray(entry?.[cleanRootKey]) ? entry[cleanRootKey] : [];
|
|
4783
|
+
const isDynamicZone = blocks.some((b) => Boolean(b?.__component));
|
|
4784
|
+
if (blocks.length === 0) return null;
|
|
4785
|
+
const occByRootIndex = /* @__PURE__ */ new Map();
|
|
4786
|
+
occurrences.forEach((occ) => {
|
|
4787
|
+
if (occ.segments?.[0]?.key !== cleanRootKey || occ.segments?.[0]?.index === void 0) return;
|
|
4788
|
+
const rootIdx = occ.segments[0].index;
|
|
4789
|
+
const list = occByRootIndex.get(rootIdx) || [];
|
|
4790
|
+
list.push(occ);
|
|
4791
|
+
occByRootIndex.set(rootIdx, list);
|
|
4792
|
+
});
|
|
4793
|
+
const allApplicableIndexes = blocks.map((_, bIdx) => bIdx).filter((bIdx) => targetsThisRoot ? (occByRootIndex.get(bIdx) || []).length > 0 : true);
|
|
4794
|
+
return /* @__PURE__ */ jsxs(
|
|
4795
|
+
Box,
|
|
4796
|
+
{
|
|
4797
|
+
padding: 3,
|
|
4798
|
+
background: "neutral0",
|
|
4799
|
+
hasRadius: true,
|
|
4800
|
+
style: { border: "1px solid rgba(73, 69, 255, 0.25)", boxShadow: "0 2px 8px rgba(0,0,0,0.05)" },
|
|
4801
|
+
children: [
|
|
4802
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 2, children: [
|
|
4803
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
|
|
4804
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "sigma", textColor: "primary700", children: [
|
|
4805
|
+
isDynamicZone ? "DYNAMIC ZONE" : "REPEATABLE COMPONENT",
|
|
4806
|
+
': "',
|
|
4807
|
+
cleanRootKey,
|
|
4808
|
+
'" (',
|
|
4809
|
+
blocks.length,
|
|
4810
|
+
" ",
|
|
4811
|
+
blocks.length === 1 ? "item" : "items",
|
|
4812
|
+
")"
|
|
4813
|
+
] }),
|
|
4814
|
+
/* @__PURE__ */ jsx(Badge, { backgroundColor: "primary100", textColor: "primary700", children: gridEditMode ? "Inline Per-Block Grid Editing" : "Selective Block Targeting" })
|
|
4815
|
+
] }),
|
|
4816
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: gridEditMode ? "Edit each occurrence independently — component IDs & sibling blocks stay intact" : "Selectively choose which blocks to update for this entry" })
|
|
4817
|
+
] }),
|
|
4818
|
+
/* @__PURE__ */ jsxs(Table, { colCount: gridEditMode ? 4 : 5, rowCount: blocks.length + 1, style: { width: "100%", background: "#fff" }, children: [
|
|
4819
|
+
/* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
|
|
4820
|
+
!gridEditMode && /* @__PURE__ */ jsx(Th, { style: { width: 64 }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Update?" }) }),
|
|
4821
|
+
/* @__PURE__ */ jsx(Th, { style: { width: 85 }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Pos / ID" }) }),
|
|
4822
|
+
/* @__PURE__ */ jsx(Th, { style: { width: 210 }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Component" }) }),
|
|
4823
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsxs(Typography, { variant: "sigma", children: [
|
|
4824
|
+
"Target Field Value (",
|
|
4825
|
+
selectedAttribute || "selected",
|
|
4826
|
+
")"
|
|
4827
|
+
] }) }),
|
|
4828
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Block Summary" }) })
|
|
4829
|
+
] }) }),
|
|
4830
|
+
/* @__PURE__ */ jsx(Tbody, { children: blocks.map((block, bIdx) => {
|
|
4831
|
+
const compUid = block?.__component || attrMeta?.component;
|
|
4832
|
+
const compLabel = formatComponentNameFriendly(compUid);
|
|
4833
|
+
const blockOccs = occByRootIndex.get(bIdx) || [];
|
|
4834
|
+
const hasTargetAttr = blockOccs.length > 0;
|
|
4835
|
+
const isBlockSelectable = targetsThisRoot ? hasTargetAttr : true;
|
|
4836
|
+
const isBlockChecked = !gridEditMode && isBlockSelectable && isSelected && (selectedDzBlocks !== void 0 ? selectedDzBlocks.includes(bIdx) : true);
|
|
4837
|
+
const hasDirtyOcc = blockOccs.some((o) => Boolean(recordEdits?.occurrences?.[o.occurrenceKey]));
|
|
4838
|
+
const blockSummaryText = block?.title || block?.name || block?.heading || block?.body || Object.keys(block || {}).filter((k) => !k.startsWith("_") && k !== "id").slice(0, 3).map((k) => {
|
|
4839
|
+
const v = block[k];
|
|
4840
|
+
if (v === null || v === void 0) return null;
|
|
4841
|
+
return `${k}: ${typeof v === "object" ? JSON.stringify(v).slice(0, 24) : String(v).slice(0, 24)}`;
|
|
4842
|
+
}).filter(Boolean).join(", ") || "-";
|
|
4843
|
+
return /* @__PURE__ */ jsxs(
|
|
4844
|
+
Tr,
|
|
4845
|
+
{
|
|
4846
|
+
style: {
|
|
4847
|
+
backgroundColor: hasDirtyOcc || isBlockChecked ? "rgba(73, 69, 255, 0.07)" : void 0
|
|
4848
|
+
},
|
|
4849
|
+
children: [
|
|
4850
|
+
!gridEditMode && /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(
|
|
4851
|
+
Checkbox,
|
|
4852
|
+
{
|
|
4853
|
+
checked: isBlockChecked,
|
|
4854
|
+
disabled: !isBlockSelectable,
|
|
4855
|
+
onCheckedChange: () => {
|
|
4856
|
+
onToggleDzBlock(colUid, entry.documentId, bIdx, allApplicableIndexes);
|
|
4857
|
+
}
|
|
4858
|
+
}
|
|
4859
|
+
) }),
|
|
4860
|
+
/* @__PURE__ */ jsxs(Td, { children: [
|
|
4861
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "pi", fontWeight: "bold", display: "block", children: [
|
|
4862
|
+
"#",
|
|
4863
|
+
bIdx
|
|
4864
|
+
] }),
|
|
4865
|
+
block?.id !== void 0 && /* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral500", style: { fontSize: "0.68rem" }, children: [
|
|
4866
|
+
"id:",
|
|
4867
|
+
block.id
|
|
4868
|
+
] })
|
|
4869
|
+
] }),
|
|
4870
|
+
/* @__PURE__ */ jsxs(Td, { children: [
|
|
4871
|
+
/* @__PURE__ */ jsx(Badge, { backgroundColor: "neutral150", textColor: "neutral800", children: compLabel }),
|
|
4872
|
+
compUid && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", display: "block", style: { fontSize: "0.68rem", marginTop: 2 }, children: compUid })
|
|
4873
|
+
] }),
|
|
4874
|
+
/* @__PURE__ */ jsx(Td, { children: !targetsThisRoot ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: selectedAttribute ? `(targets "${selectedAttribute}")` : "(select attribute to inspect)" }) : !hasTargetAttr ? /* @__PURE__ */ jsx(Badge, { backgroundColor: "neutral100", textColor: "neutral500", children: "Does not contain attribute" }) : gridEditMode ? /* @__PURE__ */ jsx(Flex, { direction: "column", gap: 2, alignItems: "flex-start", children: blockOccs.map((occ) => {
|
|
4875
|
+
const editObj = recordEdits?.occurrences?.[occ.occurrenceKey];
|
|
4876
|
+
return /* @__PURE__ */ jsxs(Box, { style: { width: "100%" }, children: [
|
|
4877
|
+
blockOccs.length > 1 && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", display: "block", style: { fontSize: "0.7rem", marginBottom: 2 }, children: occ.displayPath }),
|
|
4878
|
+
/* @__PURE__ */ jsx(
|
|
4879
|
+
GridCellEditor,
|
|
4880
|
+
{
|
|
4881
|
+
entry,
|
|
4882
|
+
attribute: selectedAttribute,
|
|
4883
|
+
occurrence: occ,
|
|
4884
|
+
attrMeta,
|
|
4885
|
+
editedValue: editObj?.value,
|
|
4886
|
+
isDirty: Boolean(editObj),
|
|
4887
|
+
validationError: editObj?.validationError,
|
|
4888
|
+
relationOptions,
|
|
4889
|
+
relationOptionsLoading,
|
|
4890
|
+
relationIsMulti,
|
|
4891
|
+
validationRules,
|
|
4892
|
+
recordEdits,
|
|
4893
|
+
colAttributes,
|
|
4894
|
+
onCommit: (o, val, err) => onCommitEdit(entry, colUid, o, val, err),
|
|
4895
|
+
onReset: (k) => onResetEdit(colUid, entry.documentId, k)
|
|
4896
|
+
}
|
|
4897
|
+
)
|
|
4898
|
+
] }, occ.occurrenceKey);
|
|
4899
|
+
}) }) : /* @__PURE__ */ jsx(Flex, { direction: "column", gap: 1, alignItems: "flex-start", children: blockOccs.map((occ) => /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", textColor: "primary700", children: occ.value !== null && occ.value !== void 0 && occ.value !== "" ? typeof occ.value === "object" ? JSON.stringify(occ.value) : String(occ.value) : "(empty / not set)" }, occ.occurrenceKey)) }) }),
|
|
4900
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(
|
|
4901
|
+
Typography,
|
|
4902
|
+
{
|
|
4903
|
+
variant: "pi",
|
|
4904
|
+
textColor: "neutral600",
|
|
4905
|
+
style: { maxWidth: 280, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
|
|
4906
|
+
children: blockSummaryText
|
|
4907
|
+
}
|
|
4908
|
+
) })
|
|
4909
|
+
]
|
|
4910
|
+
},
|
|
4911
|
+
block?.id ? `id_${block.id}_idx_${bIdx}` : `idx_${bIdx}`
|
|
4912
|
+
);
|
|
4913
|
+
}) })
|
|
4914
|
+
] })
|
|
4915
|
+
]
|
|
4916
|
+
}
|
|
4917
|
+
);
|
|
4918
|
+
}
|
|
4919
|
+
);
|
|
4920
|
+
function parseDynamicZonePath(path) {
|
|
4921
|
+
if (!path) return { cleanPath: "", rootKey: "", subPath: "" };
|
|
4922
|
+
const bracketMatch = path.match(/^([^.[]+)\[([^\]]+)\]\.(.+)$/);
|
|
4923
|
+
if (bracketMatch) {
|
|
4924
|
+
const rootKey = bracketMatch[1];
|
|
4925
|
+
const selector = bracketMatch[2];
|
|
4926
|
+
const subPath = bracketMatch[3];
|
|
4927
|
+
const cleanPath = `${rootKey}.${subPath}`;
|
|
4928
|
+
if (/^\d+$/.test(selector)) {
|
|
4929
|
+
return { cleanPath, rootKey, subPath, targetIndex: parseInt(selector, 10) };
|
|
4930
|
+
}
|
|
4931
|
+
return { cleanPath, rootKey, subPath, targetComponentUid: selector };
|
|
4932
|
+
}
|
|
4933
|
+
const parts = path.split(".");
|
|
4934
|
+
return {
|
|
4935
|
+
cleanPath: path,
|
|
4936
|
+
rootKey: parts[0] || "",
|
|
4937
|
+
subPath: parts.slice(1).join(".")
|
|
4938
|
+
};
|
|
4939
|
+
}
|
|
4940
|
+
function formatComponentName(compUid) {
|
|
4941
|
+
if (!compUid) return "Component";
|
|
4942
|
+
const name = compUid.includes(".") ? compUid.split(".")[1] : compUid;
|
|
4943
|
+
return name.split(/[-_]/).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
4944
|
+
}
|
|
4945
|
+
function getAllNestedValues(obj, path, availableAttributes) {
|
|
4946
|
+
if (!obj || !path) return [];
|
|
4947
|
+
const parsed = parseDynamicZonePath(path);
|
|
4948
|
+
const parts = parsed.cleanPath.split(".");
|
|
4949
|
+
const [head, ...tail] = parts;
|
|
4950
|
+
const rootTarget = getPropertyValue(obj, head);
|
|
4951
|
+
if (Array.isArray(rootTarget)) {
|
|
4952
|
+
const results = [];
|
|
4953
|
+
rootTarget.forEach((item, idx) => {
|
|
4954
|
+
if (!item || typeof item !== "object") return;
|
|
4955
|
+
if (parsed.targetIndex !== void 0 && idx !== parsed.targetIndex) return;
|
|
4956
|
+
if (parsed.targetComponentUid && item.__component !== parsed.targetComponentUid) return;
|
|
4957
|
+
const subPath = tail.join(".");
|
|
4958
|
+
const scopedPath = item.__component ? `${head}[${item.__component}].${subPath}` : "";
|
|
4959
|
+
const isSupported = availableAttributes ? availableAttributes.includes(scopedPath) : false;
|
|
4960
|
+
const subVal = tail.length > 0 ? getNestedValue(item, subPath) : item;
|
|
4961
|
+
if (subVal !== void 0 || isSupported) {
|
|
4962
|
+
results.push({
|
|
4963
|
+
index: idx,
|
|
4964
|
+
componentUid: item.__component,
|
|
4965
|
+
componentName: formatComponentName(item.__component),
|
|
4966
|
+
value: subVal !== void 0 ? subVal : null,
|
|
4967
|
+
path: `${head}[#${idx}${item.__component ? ` ${formatComponentName(item.__component)}` : ""}].${subPath}`
|
|
4968
|
+
});
|
|
4969
|
+
}
|
|
4970
|
+
});
|
|
4971
|
+
return results;
|
|
4972
|
+
}
|
|
4973
|
+
const singleVal = getNestedValue(obj, parsed.cleanPath);
|
|
4974
|
+
if (singleVal !== void 0) {
|
|
4975
|
+
return [
|
|
4976
|
+
{
|
|
4977
|
+
index: 0,
|
|
4978
|
+
value: singleVal,
|
|
4979
|
+
path: parsed.cleanPath
|
|
4980
|
+
}
|
|
4981
|
+
];
|
|
4982
|
+
}
|
|
4983
|
+
return [];
|
|
4984
|
+
}
|
|
4985
|
+
function getPropertyValue(target, key) {
|
|
4986
|
+
if (!target || typeof target !== "object" || !key) return void 0;
|
|
4987
|
+
if (target[key] !== void 0 && target[key] !== null) return target[key];
|
|
4988
|
+
const camelKey = key.replace(/_([a-z0-9])/g, (_, letter) => letter.toUpperCase());
|
|
4989
|
+
if (target[camelKey] !== void 0 && target[camelKey] !== null) return target[camelKey];
|
|
4990
|
+
const snakeKey = key.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
4991
|
+
if (target[snakeKey] !== void 0 && target[snakeKey] !== null) return target[snakeKey];
|
|
4992
|
+
const lowerKey = key.toLowerCase();
|
|
4993
|
+
const lowerNoUnderscore = lowerKey.replace(/_/g, "");
|
|
4994
|
+
const matchedKey = Object.keys(target).find((k) => {
|
|
4995
|
+
const kLower = k.toLowerCase();
|
|
4996
|
+
return kLower === lowerKey || kLower.replace(/_/g, "") === lowerNoUnderscore;
|
|
4997
|
+
});
|
|
4998
|
+
if (matchedKey && target[matchedKey] !== void 0 && target[matchedKey] !== null) {
|
|
4999
|
+
return target[matchedKey];
|
|
5000
|
+
}
|
|
5001
|
+
if (key in target) return target[key];
|
|
5002
|
+
if (camelKey in target) return target[camelKey];
|
|
5003
|
+
if (snakeKey in target) return target[snakeKey];
|
|
5004
|
+
return void 0;
|
|
5005
|
+
}
|
|
5006
|
+
function getNestedValue(obj, path) {
|
|
5007
|
+
if (!obj || !path) return void 0;
|
|
5008
|
+
const parsed = parseDynamicZonePath(path);
|
|
5009
|
+
const parts = parsed.cleanPath.split(".");
|
|
5010
|
+
function extract(current, remainingParts) {
|
|
5011
|
+
if (current === void 0 || current === null) return void 0;
|
|
5012
|
+
if (remainingParts.length === 0) return current;
|
|
5013
|
+
const [head, ...tail] = remainingParts;
|
|
5014
|
+
if (Array.isArray(current)) {
|
|
5015
|
+
if (/^\d+$/.test(head)) {
|
|
5016
|
+
return extract(current[parseInt(head, 10)], tail);
|
|
5017
|
+
}
|
|
5018
|
+
for (let idx = 0; idx < current.length; idx++) {
|
|
5019
|
+
const item = current[idx];
|
|
5020
|
+
if (parsed.targetIndex !== void 0 && idx !== parsed.targetIndex) continue;
|
|
5021
|
+
if (parsed.targetComponentUid && item?.__component !== parsed.targetComponentUid) continue;
|
|
5022
|
+
const found = extract(getPropertyValue(item, head), tail);
|
|
5023
|
+
if (found !== void 0 && found !== null) return found;
|
|
5024
|
+
}
|
|
5025
|
+
return void 0;
|
|
5026
|
+
}
|
|
5027
|
+
return extract(getPropertyValue(current, head), tail);
|
|
5028
|
+
}
|
|
5029
|
+
return extract(obj, parts);
|
|
5030
|
+
}
|
|
5031
|
+
function getAvailableColumnsForCollection(col, selectedAttribute, searchAttribute) {
|
|
5032
|
+
const cols = [
|
|
5033
|
+
{
|
|
5034
|
+
key: "select",
|
|
5035
|
+
label: "Select",
|
|
5036
|
+
isPermanent: true,
|
|
5037
|
+
defaultVisible: true
|
|
5038
|
+
},
|
|
5039
|
+
{
|
|
5040
|
+
key: "identifier",
|
|
5041
|
+
label: "Identifier",
|
|
5042
|
+
sortable: !col.isSingleType,
|
|
5043
|
+
defaultVisible: true
|
|
5044
|
+
}
|
|
5045
|
+
];
|
|
5046
|
+
const candidateAttrs = col.attributes || [];
|
|
5047
|
+
candidateAttrs.forEach((attr) => {
|
|
5048
|
+
if (attr === "name" || attr === "title" || attr === selectedAttribute || searchAttribute && attr === searchAttribute) {
|
|
5049
|
+
return;
|
|
5050
|
+
}
|
|
5051
|
+
let formattedLabel = attr;
|
|
5052
|
+
if (attr === "updated_at" || attr === "updatedAt") {
|
|
5053
|
+
formattedLabel = "Updated At";
|
|
5054
|
+
} else if (attr === "created_at" || attr === "createdAt") {
|
|
5055
|
+
formattedLabel = "Created At";
|
|
5056
|
+
} else if (attr === "published_at" || attr === "publishedAt") {
|
|
5057
|
+
formattedLabel = "Published At";
|
|
5058
|
+
} else {
|
|
5059
|
+
const bracketMatch = attr.match(/^([^.[]+)\[([^\]]+)\]\.(.+)$/);
|
|
3452
5060
|
if (bracketMatch) {
|
|
3453
5061
|
const root = bracketMatch[1].charAt(0).toUpperCase() + bracketMatch[1].slice(1);
|
|
3454
5062
|
const comp = formatComponentName(bracketMatch[2]);
|
|
@@ -3721,7 +5329,7 @@ function formatDisplayValue(val) {
|
|
|
3721
5329
|
}
|
|
3722
5330
|
return String(val);
|
|
3723
5331
|
}
|
|
3724
|
-
function renderCellContent(colDef, entry, col, selectedAttribute, searchAttribute, isMatch, hasAttr, isSelected, onToggleSelect, pendingBatches = [], isDzExpanded = false, onToggleExpandDz, filterQuery = "") {
|
|
5332
|
+
function renderCellContent(colDef, entry, col, selectedAttribute, searchAttribute, isMatch, hasAttr, isSelected, onToggleSelect, pendingBatches = [], isDzExpanded = false, onToggleExpandDz, filterQuery = "", gridCtx) {
|
|
3725
5333
|
switch (colDef.key) {
|
|
3726
5334
|
case "select":
|
|
3727
5335
|
return /* @__PURE__ */ jsx(
|
|
@@ -3736,7 +5344,10 @@ function renderCellContent(colDef, entry, col, selectedAttribute, searchAttribut
|
|
|
3736
5344
|
const dzField = Object.keys(entry).find(
|
|
3737
5345
|
(k) => Array.isArray(entry[k]) && entry[k].length > 0 && entry[k].some((item) => item && item.__component)
|
|
3738
5346
|
);
|
|
3739
|
-
const
|
|
5347
|
+
const selectedRootKey = selectedAttribute ? selectedAttribute.split("[")[0].split(".")[0] : "";
|
|
5348
|
+
const repeatableRoot = !dzField && gridCtx?.gridEditMode && selectedRootKey && gridCtx?.selectedAttrMeta?.rootRepeatable && Array.isArray(entry[selectedRootKey]) && entry[selectedRootKey].length > 0 ? selectedRootKey : void 0;
|
|
5349
|
+
const expandField = dzField || repeatableRoot;
|
|
5350
|
+
const dzItemsCount = expandField ? entry[expandField].length : 0;
|
|
3740
5351
|
return /* @__PURE__ */ jsxs(Box, { children: [
|
|
3741
5352
|
/* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", children: mainText }),
|
|
3742
5353
|
entry.email && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", display: "block", children: entry.email }),
|
|
@@ -3754,7 +5365,7 @@ function renderCellContent(colDef, entry, col, selectedAttribute, searchAttribut
|
|
|
3754
5365
|
backgroundColor: isDzExpanded ? "rgba(73, 69, 255, 0.08)" : "rgba(0, 0, 0, 0.04)",
|
|
3755
5366
|
borderRadius: 4
|
|
3756
5367
|
},
|
|
3757
|
-
children: isDzExpanded ? `▲ Hide ${
|
|
5368
|
+
children: isDzExpanded ? `▲ Hide ${expandField} (${dzItemsCount} ${dzField ? "blocks" : "items"})` : `▼ ${gridCtx?.gridEditMode ? "Edit" : "View"} ${expandField} (${dzItemsCount} ${dzField ? "blocks" : "items"})`
|
|
3758
5369
|
}
|
|
3759
5370
|
) })
|
|
3760
5371
|
] });
|
|
@@ -3821,13 +5432,95 @@ function renderCellContent(colDef, entry, col, selectedAttribute, searchAttribut
|
|
|
3821
5432
|
children: displayStr
|
|
3822
5433
|
}
|
|
3823
5434
|
)
|
|
3824
|
-
]
|
|
3825
|
-
},
|
|
3826
|
-
m.index
|
|
3827
|
-
);
|
|
3828
|
-
}) });
|
|
3829
|
-
}
|
|
3830
|
-
case "target_attr": {
|
|
5435
|
+
]
|
|
5436
|
+
},
|
|
5437
|
+
m.index
|
|
5438
|
+
);
|
|
5439
|
+
}) });
|
|
5440
|
+
}
|
|
5441
|
+
case "target_attr": {
|
|
5442
|
+
if (gridCtx?.gridEditMode) {
|
|
5443
|
+
if (selectedAttribute && !hasAttr) {
|
|
5444
|
+
return /* @__PURE__ */ jsx(Badge, { backgroundColor: "neutral200", textColor: "neutral600", children: "Ignored (absent in schema)" });
|
|
5445
|
+
}
|
|
5446
|
+
const occs = enumerateClientOccurrences(
|
|
5447
|
+
entry,
|
|
5448
|
+
selectedAttribute,
|
|
5449
|
+
col?.attributes,
|
|
5450
|
+
gridCtx.selectedAttrMeta
|
|
5451
|
+
);
|
|
5452
|
+
if (occs.length === 0) {
|
|
5453
|
+
return /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", style: { fontStyle: "italic" }, children: "(no applicable block / item)" });
|
|
5454
|
+
}
|
|
5455
|
+
if (occs.length === 1 && !occs[0].segments.some((s) => s.index !== void 0)) {
|
|
5456
|
+
const occ = occs[0];
|
|
5457
|
+
const editObj = gridCtx.recordEdits?.occurrences?.[occ.occurrenceKey];
|
|
5458
|
+
return /* @__PURE__ */ jsx(
|
|
5459
|
+
GridCellEditor,
|
|
5460
|
+
{
|
|
5461
|
+
entry,
|
|
5462
|
+
attribute: selectedAttribute,
|
|
5463
|
+
occurrence: occ,
|
|
5464
|
+
attrMeta: gridCtx.selectedAttrMeta,
|
|
5465
|
+
editedValue: editObj?.value,
|
|
5466
|
+
isDirty: Boolean(editObj),
|
|
5467
|
+
validationError: editObj?.validationError,
|
|
5468
|
+
relationOptions: gridCtx.relationOptions,
|
|
5469
|
+
relationOptionsLoading: gridCtx.relationOptionsLoading,
|
|
5470
|
+
relationIsMulti: gridCtx.relationIsMulti,
|
|
5471
|
+
validationRules: gridCtx.validationRules,
|
|
5472
|
+
recordEdits: gridCtx.recordEdits,
|
|
5473
|
+
colAttributes: col?.attributes,
|
|
5474
|
+
onCommit: (o, val, err) => gridCtx.onCommitEdit(entry, col.uid, o, val, err),
|
|
5475
|
+
onReset: (k) => gridCtx.onResetEdit(col.uid, entry.documentId, k)
|
|
5476
|
+
}
|
|
5477
|
+
);
|
|
5478
|
+
}
|
|
5479
|
+
const maxInline = 3;
|
|
5480
|
+
const visibleOccs = occs.slice(0, maxInline);
|
|
5481
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, alignItems: "flex-start", children: [
|
|
5482
|
+
visibleOccs.map((occ) => {
|
|
5483
|
+
const editObj = gridCtx.recordEdits?.occurrences?.[occ.occurrenceKey];
|
|
5484
|
+
return /* @__PURE__ */ jsxs(Box, { style: { width: "100%" }, children: [
|
|
5485
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", marginBottom: 1, children: [
|
|
5486
|
+
/* @__PURE__ */ jsxs(Badge, { size: "S", backgroundColor: editObj ? "primary100" : "neutral200", textColor: editObj ? "primary700" : "neutral800", children: [
|
|
5487
|
+
"#",
|
|
5488
|
+
occ.index,
|
|
5489
|
+
" ",
|
|
5490
|
+
occ.componentName || "Item"
|
|
5491
|
+
] }),
|
|
5492
|
+
occ.componentId !== void 0 && /* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral500", style: { fontSize: "0.68rem" }, children: [
|
|
5493
|
+
"id:",
|
|
5494
|
+
occ.componentId
|
|
5495
|
+
] }),
|
|
5496
|
+
editObj && /* @__PURE__ */ jsx(Badge, { size: "S", backgroundColor: "secondary100", textColor: "secondary700", children: "Edited" })
|
|
5497
|
+
] }),
|
|
5498
|
+
/* @__PURE__ */ jsx(
|
|
5499
|
+
GridCellEditor,
|
|
5500
|
+
{
|
|
5501
|
+
compact: true,
|
|
5502
|
+
entry,
|
|
5503
|
+
attribute: selectedAttribute,
|
|
5504
|
+
occurrence: occ,
|
|
5505
|
+
attrMeta: gridCtx.selectedAttrMeta,
|
|
5506
|
+
editedValue: editObj?.value,
|
|
5507
|
+
isDirty: Boolean(editObj),
|
|
5508
|
+
validationError: editObj?.validationError,
|
|
5509
|
+
relationOptions: gridCtx.relationOptions,
|
|
5510
|
+
relationOptionsLoading: gridCtx.relationOptionsLoading,
|
|
5511
|
+
relationIsMulti: gridCtx.relationIsMulti,
|
|
5512
|
+
validationRules: gridCtx.validationRules,
|
|
5513
|
+
recordEdits: gridCtx.recordEdits,
|
|
5514
|
+
colAttributes: col?.attributes,
|
|
5515
|
+
onCommit: (o, val, err) => gridCtx.onCommitEdit(entry, col.uid, o, val, err),
|
|
5516
|
+
onReset: (k) => gridCtx.onResetEdit(col.uid, entry.documentId, k)
|
|
5517
|
+
}
|
|
5518
|
+
)
|
|
5519
|
+
] }, occ.occurrenceKey);
|
|
5520
|
+
}),
|
|
5521
|
+
occs.length > maxInline && onToggleExpandDz && /* @__PURE__ */ jsx(Button, { variant: "tertiary", size: "S", onClick: onToggleExpandDz, children: isDzExpanded ? `▲ Collapse drawer` : `▼ Edit all ${occs.length} occurrences in drawer` })
|
|
5522
|
+
] });
|
|
5523
|
+
}
|
|
3831
5524
|
const matches = getAllNestedValues(entry, selectedAttribute, col?.attributes);
|
|
3832
5525
|
if (matches.length === 0) {
|
|
3833
5526
|
return /* @__PURE__ */ jsx(Typography, { textColor: "neutral500", style: { fontStyle: "italic" }, children: "(empty / not set)" });
|
|
@@ -4034,6 +5727,10 @@ const BulkUpdater = () => {
|
|
|
4034
5727
|
const [searchAttribute, setSearchAttribute] = useState("");
|
|
4035
5728
|
const [searchAttributeInput, setSearchAttributeInput] = useState("");
|
|
4036
5729
|
const [attributesMeta, setAttributesMeta] = useState({});
|
|
5730
|
+
const [gridEditMode, setGridEditMode] = useState(false);
|
|
5731
|
+
const [gridEdits, setGridEdits] = useState({});
|
|
5732
|
+
const [gridFilterModifiedOnly, setGridFilterModifiedOnly] = useState(false);
|
|
5733
|
+
const [validationRules, setValidationRules] = useState([]);
|
|
4037
5734
|
const effectiveSearchAttribute = searchAttribute || selectedAttribute;
|
|
4038
5735
|
useEffect(() => {
|
|
4039
5736
|
if (effectiveSearchAttribute && relationsMeta[effectiveSearchAttribute]) {
|
|
@@ -4348,10 +6045,20 @@ const BulkUpdater = () => {
|
|
|
4348
6045
|
setPendingBatchesLoading(false);
|
|
4349
6046
|
}
|
|
4350
6047
|
};
|
|
6048
|
+
const fetchValidationRules = async () => {
|
|
6049
|
+
try {
|
|
6050
|
+
const res = await get("/bulk-updater/validation-rules");
|
|
6051
|
+
if (res.data?.success && Array.isArray(res.data.rules)) {
|
|
6052
|
+
setValidationRules(res.data.rules);
|
|
6053
|
+
}
|
|
6054
|
+
} catch {
|
|
6055
|
+
}
|
|
6056
|
+
};
|
|
4351
6057
|
useEffect(() => {
|
|
4352
6058
|
fetchModels();
|
|
4353
6059
|
fetchAuditHistory();
|
|
4354
6060
|
fetchPendingBatches();
|
|
6061
|
+
fetchValidationRules();
|
|
4355
6062
|
}, []);
|
|
4356
6063
|
useEffect(() => {
|
|
4357
6064
|
if (activeTab === "audit") {
|
|
@@ -4369,7 +6076,17 @@ const BulkUpdater = () => {
|
|
|
4369
6076
|
if (selectedCollectionUid) {
|
|
4370
6077
|
const isFilterActiveNow = Boolean(searchAttribute && searchAttribute !== selectedAttribute) || filterOperator !== "none" && (["empty", "not_empty"].includes(filterOperator) || Boolean(filterQuery.trim())) || Boolean(entrySearch.trim()) || Boolean(useRegex && regexPattern.trim());
|
|
4371
6078
|
if (isFilterActiveNow) {
|
|
4372
|
-
|
|
6079
|
+
if (gridEditMode) {
|
|
6080
|
+
setSelectedEntries((prev) => {
|
|
6081
|
+
const retained = {};
|
|
6082
|
+
Object.keys(gridEdits).forEach((k) => {
|
|
6083
|
+
if (prev[k]) retained[k] = true;
|
|
6084
|
+
});
|
|
6085
|
+
return retained;
|
|
6086
|
+
});
|
|
6087
|
+
} else {
|
|
6088
|
+
setSelectedEntries({});
|
|
6089
|
+
}
|
|
4373
6090
|
}
|
|
4374
6091
|
loadCollectionPage(
|
|
4375
6092
|
selectedCollectionUid,
|
|
@@ -4392,12 +6109,131 @@ const BulkUpdater = () => {
|
|
|
4392
6109
|
if (!collections.length || !selectedCollectionUid) return null;
|
|
4393
6110
|
return collections.find((c) => c.uid === selectedCollectionUid) || null;
|
|
4394
6111
|
}, [collections, selectedCollectionUid]);
|
|
6112
|
+
const activeAttrMeta = useMemo(() => {
|
|
6113
|
+
if (!selectedAttribute) return void 0;
|
|
6114
|
+
const base = selectedCol?.attributesMeta?.[selectedAttribute] || attributesMeta[selectedAttribute];
|
|
6115
|
+
const relMeta = selectedCol?.relations?.[selectedAttribute] || relationsMeta[selectedAttribute];
|
|
6116
|
+
if (!base && !relMeta) return void 0;
|
|
6117
|
+
if (relMeta && (!base || !base.isRelation)) {
|
|
6118
|
+
return {
|
|
6119
|
+
...base || { depth: 0, type: "relation" },
|
|
6120
|
+
isRelation: true,
|
|
6121
|
+
relationType: relMeta.relationType,
|
|
6122
|
+
target: relMeta.targetUid
|
|
6123
|
+
};
|
|
6124
|
+
}
|
|
6125
|
+
return base;
|
|
6126
|
+
}, [selectedAttribute, selectedCol, attributesMeta, relationsMeta]);
|
|
6127
|
+
const totalDirtyRecordsCount = useMemo(() => Object.keys(gridEdits).length, [gridEdits]);
|
|
6128
|
+
const totalDirtyCellsCount = useMemo(
|
|
6129
|
+
() => Object.values(gridEdits).reduce(
|
|
6130
|
+
(sum, rec) => sum + Object.keys(rec.occurrences || {}).length,
|
|
6131
|
+
0
|
|
6132
|
+
),
|
|
6133
|
+
[gridEdits]
|
|
6134
|
+
);
|
|
6135
|
+
const gridSerialized = useMemo(
|
|
6136
|
+
() => serializeGridTargets(gridEdits, selectedEntries, collectionPages, activeAttrMeta),
|
|
6137
|
+
[gridEdits, selectedEntries, collectionPages, activeAttrMeta]
|
|
6138
|
+
);
|
|
6139
|
+
const handleGridCellCommit = React__default.useCallback(
|
|
6140
|
+
(entry, colUid, occ, newValue, validationError) => {
|
|
6141
|
+
const key = `${colUid}${KEY_SEP}${entry.documentId}`;
|
|
6142
|
+
const recordLabel = entry.name || entry.title || entry.email || `Entry #${entry.id || entry.documentId}`;
|
|
6143
|
+
setGridEdits((prev) => {
|
|
6144
|
+
const existingRec = prev[key] || {
|
|
6145
|
+
uid: colUid,
|
|
6146
|
+
documentId: entry.documentId,
|
|
6147
|
+
locale: entry.locale,
|
|
6148
|
+
status: entry.status,
|
|
6149
|
+
publishedAt: entry.publishedAt,
|
|
6150
|
+
recordLabel,
|
|
6151
|
+
occurrences: {}
|
|
6152
|
+
};
|
|
6153
|
+
return {
|
|
6154
|
+
...prev,
|
|
6155
|
+
[key]: {
|
|
6156
|
+
...existingRec,
|
|
6157
|
+
occurrences: {
|
|
6158
|
+
...existingRec.occurrences,
|
|
6159
|
+
[occ.occurrenceKey]: {
|
|
6160
|
+
occurrenceKey: occ.occurrenceKey,
|
|
6161
|
+
displayPath: occ.displayPath,
|
|
6162
|
+
segments: occ.segments,
|
|
6163
|
+
originalValue: occ.value,
|
|
6164
|
+
value: newValue,
|
|
6165
|
+
fieldType: activeAttrMeta?.type || "string",
|
|
6166
|
+
validationError,
|
|
6167
|
+
touchedAt: Date.now()
|
|
6168
|
+
}
|
|
6169
|
+
}
|
|
6170
|
+
}
|
|
6171
|
+
};
|
|
6172
|
+
});
|
|
6173
|
+
setSelectedEntries((prev) => prev[key] ? prev : { ...prev, [key]: true });
|
|
6174
|
+
},
|
|
6175
|
+
[activeAttrMeta?.type]
|
|
6176
|
+
);
|
|
6177
|
+
const handleGridCellReset = React__default.useCallback((colUid, documentId, occKey) => {
|
|
6178
|
+
const key = `${colUid}${KEY_SEP}${documentId}`;
|
|
6179
|
+
setGridEdits((prev) => {
|
|
6180
|
+
const existingRec = prev[key];
|
|
6181
|
+
if (!existingRec) return prev;
|
|
6182
|
+
const nextOccs = { ...existingRec.occurrences };
|
|
6183
|
+
delete nextOccs[occKey];
|
|
6184
|
+
if (Object.keys(nextOccs).length === 0) {
|
|
6185
|
+
const next = { ...prev };
|
|
6186
|
+
delete next[key];
|
|
6187
|
+
return next;
|
|
6188
|
+
}
|
|
6189
|
+
return {
|
|
6190
|
+
...prev,
|
|
6191
|
+
[key]: {
|
|
6192
|
+
...existingRec,
|
|
6193
|
+
occurrences: nextOccs
|
|
6194
|
+
}
|
|
6195
|
+
};
|
|
6196
|
+
});
|
|
6197
|
+
}, []);
|
|
6198
|
+
const handleToggleGridEditMode = (checked) => {
|
|
6199
|
+
if (!checked && totalDirtyCellsCount > 0) {
|
|
6200
|
+
if (!window.confirm(`Disable Grid Editing Mode and discard ${totalDirtyCellsCount} unsaved edit(s)?`)) {
|
|
6201
|
+
return;
|
|
6202
|
+
}
|
|
6203
|
+
setGridEdits({});
|
|
6204
|
+
}
|
|
6205
|
+
setGridEditMode(checked);
|
|
6206
|
+
setGridFilterModifiedOnly(false);
|
|
6207
|
+
if (checked) {
|
|
6208
|
+
if (useRegex) setUseRegex(false);
|
|
6209
|
+
setRegexPattern("");
|
|
6210
|
+
if (selectedCollectionUid) {
|
|
6211
|
+
setCollectionColumnVisibility((prev) => {
|
|
6212
|
+
const existing = prev[selectedCollectionUid];
|
|
6213
|
+
if (existing && !existing.includes("target_attr")) {
|
|
6214
|
+
return { ...prev, [selectedCollectionUid]: [...existing, "target_attr"] };
|
|
6215
|
+
}
|
|
6216
|
+
return prev;
|
|
6217
|
+
});
|
|
6218
|
+
}
|
|
6219
|
+
}
|
|
6220
|
+
};
|
|
4395
6221
|
const handleCollectionChange = (newUid) => {
|
|
4396
6222
|
if (newUid === selectedCollectionUid) return;
|
|
6223
|
+
if (totalDirtyCellsCount > 0) {
|
|
6224
|
+
if (!window.confirm(
|
|
6225
|
+
`You have ${totalDirtyCellsCount} unsaved Grid Edit(s) in the current collection. Switching collections will discard them. Continue?`
|
|
6226
|
+
)) {
|
|
6227
|
+
return;
|
|
6228
|
+
}
|
|
6229
|
+
}
|
|
4397
6230
|
if (abortControllersRef.current) {
|
|
4398
|
-
Object.values(abortControllersRef.current).forEach((ctrl) => ctrl
|
|
6231
|
+
Object.values(abortControllersRef.current).forEach((ctrl) => ctrl?.abort());
|
|
4399
6232
|
}
|
|
4400
6233
|
setSelectedCollectionUid(newUid);
|
|
6234
|
+
setGridEdits({});
|
|
6235
|
+
setSelectedDzBlocks({});
|
|
6236
|
+
setExpandedDzEntries({});
|
|
4401
6237
|
try {
|
|
4402
6238
|
if (newUid) {
|
|
4403
6239
|
localStorage.setItem(LAST_COLLECTION_KEY, newUid);
|
|
@@ -4431,6 +6267,14 @@ const BulkUpdater = () => {
|
|
|
4431
6267
|
};
|
|
4432
6268
|
const handleAttributeChange = (newAttr) => {
|
|
4433
6269
|
if (newAttr !== selectedAttribute) {
|
|
6270
|
+
if (totalDirtyCellsCount > 0) {
|
|
6271
|
+
if (!window.confirm(
|
|
6272
|
+
`You have ${totalDirtyCellsCount} unsaved Grid Edit(s) for "${selectedAttribute}". Switching Target Attribute will discard them. Continue?`
|
|
6273
|
+
)) {
|
|
6274
|
+
return;
|
|
6275
|
+
}
|
|
6276
|
+
}
|
|
6277
|
+
setGridEdits({});
|
|
4434
6278
|
setSelectedAttribute(newAttr);
|
|
4435
6279
|
try {
|
|
4436
6280
|
if (newAttr) {
|
|
@@ -4452,13 +6296,13 @@ const BulkUpdater = () => {
|
|
|
4452
6296
|
const filteredCollections = useMemo(() => {
|
|
4453
6297
|
return selectedCol ? [selectedCol] : [];
|
|
4454
6298
|
}, [selectedCol]);
|
|
4455
|
-
const getAttrDepth = (attr) => attributesMeta[attr]?.depth ?? (attr.includes(".") ? attr.split(".").length - 1 : 0);
|
|
6299
|
+
const getAttrDepth = (attr) => selectedCol?.attributesMeta?.[attr]?.depth ?? attributesMeta[attr]?.depth ?? (attr.includes(".") ? attr.split(".").length - 1 : 0);
|
|
4456
6300
|
const availableColAttributes = useMemo(() => {
|
|
4457
6301
|
return selectedCol?.attributes || attributes || [];
|
|
4458
6302
|
}, [selectedCol, attributes]);
|
|
4459
6303
|
const depthFilteredAttributes = useMemo(() => {
|
|
4460
6304
|
return availableColAttributes.filter((attr) => getAttrDepth(attr) <= componentDepth);
|
|
4461
|
-
}, [availableColAttributes, componentDepth, attributesMeta]);
|
|
6305
|
+
}, [availableColAttributes, componentDepth, attributesMeta, selectedCol]);
|
|
4462
6306
|
const memoizedComboboxOptions = useMemo(() => {
|
|
4463
6307
|
if (depthFilteredAttributes.length === 0) {
|
|
4464
6308
|
return /* @__PURE__ */ jsx(ComboboxOption, { value: "__none__", disabled: true, textValue: "No attributes available", children: /* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral600", children: [
|
|
@@ -4639,7 +6483,10 @@ const BulkUpdater = () => {
|
|
|
4639
6483
|
};
|
|
4640
6484
|
const getVisibleEntries = (col) => {
|
|
4641
6485
|
const pageState = collectionPages[col.uid];
|
|
4642
|
-
|
|
6486
|
+
let raw = pageState ? pageState.entries : col.entries || [];
|
|
6487
|
+
if (gridEditMode && gridFilterModifiedOnly) {
|
|
6488
|
+
raw = raw.filter((entry) => Boolean(gridEdits[`${col.uid}${KEY_SEP}${entry.documentId}`]));
|
|
6489
|
+
}
|
|
4643
6490
|
if (statusFilter === "all") return raw;
|
|
4644
6491
|
return raw.filter((entry) => {
|
|
4645
6492
|
const lifecycle = getEntryLifecycleStatus(entry, col, pendingBatches);
|
|
@@ -4653,7 +6500,7 @@ const BulkUpdater = () => {
|
|
|
4653
6500
|
count += getVisibleEntries(col).length;
|
|
4654
6501
|
});
|
|
4655
6502
|
return count;
|
|
4656
|
-
}, [filteredCollections, collectionPages, isFilterActive, statusFilter, pendingBatches]);
|
|
6503
|
+
}, [filteredCollections, collectionPages, isFilterActive, statusFilter, pendingBatches, gridEditMode, gridFilterModifiedOnly, gridEdits]);
|
|
4657
6504
|
const selectAllMatching = () => {
|
|
4658
6505
|
const updated = { ...selectedEntries };
|
|
4659
6506
|
filteredCollections.forEach((col) => {
|
|
@@ -4681,7 +6528,17 @@ const BulkUpdater = () => {
|
|
|
4681
6528
|
setEntrySearch("");
|
|
4682
6529
|
setStatusFilter("all");
|
|
4683
6530
|
setRegexPattern("");
|
|
4684
|
-
|
|
6531
|
+
if (gridEditMode) {
|
|
6532
|
+
setSelectedEntries((prev) => {
|
|
6533
|
+
const retained = {};
|
|
6534
|
+
Object.keys(gridEdits).forEach((k) => {
|
|
6535
|
+
if (prev[k]) retained[k] = true;
|
|
6536
|
+
});
|
|
6537
|
+
return retained;
|
|
6538
|
+
});
|
|
6539
|
+
} else {
|
|
6540
|
+
setSelectedEntries({});
|
|
6541
|
+
}
|
|
4685
6542
|
collections.forEach((col) => {
|
|
4686
6543
|
loadCollectionPage(col.uid, 1, void 0, void 0, void 0, "none", "", "", false, "");
|
|
4687
6544
|
});
|
|
@@ -4726,58 +6583,71 @@ const BulkUpdater = () => {
|
|
|
4726
6583
|
const deselectAll = () => {
|
|
4727
6584
|
setSelectedEntries({});
|
|
4728
6585
|
};
|
|
4729
|
-
const getSelectedBreakdown = () => {
|
|
6586
|
+
const getSelectedBreakdown = (onlyKeys) => {
|
|
4730
6587
|
const breakdown = {};
|
|
4731
|
-
Object.keys(selectedEntries).
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
}
|
|
6588
|
+
const keysToCount = onlyKeys || Object.keys(selectedEntries).filter((k) => selectedEntries[k]);
|
|
6589
|
+
keysToCount.forEach((key) => {
|
|
6590
|
+
const parts = key.split(KEY_SEP);
|
|
6591
|
+
if (parts.length === 2) {
|
|
6592
|
+
const uid = parts[0];
|
|
6593
|
+
const col = collections.find((c) => c.uid === uid);
|
|
6594
|
+
const name = col?.displayName || uid;
|
|
6595
|
+
breakdown[name] = (breakdown[name] || 0) + 1;
|
|
4740
6596
|
}
|
|
4741
6597
|
});
|
|
4742
6598
|
return breakdown;
|
|
4743
6599
|
};
|
|
4744
|
-
const
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
6600
|
+
const computeLifecycleStatsForKeys = React__default.useCallback(
|
|
6601
|
+
(keys) => {
|
|
6602
|
+
let published = 0;
|
|
6603
|
+
let modified = 0;
|
|
6604
|
+
let draft = 0;
|
|
6605
|
+
let pendingReview = 0;
|
|
6606
|
+
let unknown = 0;
|
|
6607
|
+
keys.forEach((key) => {
|
|
6608
|
+
const parts = key.split(KEY_SEP);
|
|
6609
|
+
if (parts.length !== 2) return;
|
|
6610
|
+
const [uid, docId] = parts;
|
|
6611
|
+
const col = collections.find((c) => c.uid === uid) || null;
|
|
6612
|
+
const entry = collectionPages[uid]?.entries?.find((e) => e.documentId === docId || String(e.id) === docId) || col?.entries?.find((e) => e.documentId === docId || String(e.id) === docId);
|
|
6613
|
+
if (col && col.draftAndPublish === false) {
|
|
6614
|
+
published++;
|
|
6615
|
+
} else if (entry) {
|
|
6616
|
+
const { status } = getEntryLifecycleStatus(entry, col, pendingBatches);
|
|
6617
|
+
if (status === "published") published++;
|
|
6618
|
+
else if (status === "modified") modified++;
|
|
6619
|
+
else if (status === "draft") draft++;
|
|
6620
|
+
else if (status === "pending_review") pendingReview++;
|
|
6621
|
+
else unknown++;
|
|
6622
|
+
} else {
|
|
6623
|
+
draft++;
|
|
6624
|
+
}
|
|
6625
|
+
});
|
|
6626
|
+
const unreviewedCount = draft + modified + pendingReview + unknown;
|
|
6627
|
+
return {
|
|
6628
|
+
published,
|
|
6629
|
+
modified,
|
|
6630
|
+
draft,
|
|
6631
|
+
pendingReview,
|
|
6632
|
+
unknown,
|
|
6633
|
+
unreviewedCount,
|
|
6634
|
+
total: published + modified + draft + pendingReview + unknown
|
|
6635
|
+
};
|
|
6636
|
+
},
|
|
6637
|
+
[collections, collectionPages, pendingBatches]
|
|
6638
|
+
);
|
|
6639
|
+
const selectedLifecycleStats = useMemo(
|
|
6640
|
+
() => computeLifecycleStatsForKeys(Object.keys(selectedEntries).filter((k) => selectedEntries[k])),
|
|
6641
|
+
[selectedEntries, computeLifecycleStatsForKeys]
|
|
6642
|
+
);
|
|
6643
|
+
const gridTargetKeys = useMemo(
|
|
6644
|
+
() => gridSerialized.targets.map((t) => `${t.uid}${KEY_SEP}${t.documentId}`),
|
|
6645
|
+
[gridSerialized]
|
|
6646
|
+
);
|
|
6647
|
+
const updateModalLifecycleStats = useMemo(
|
|
6648
|
+
() => gridEditMode ? computeLifecycleStatsForKeys(gridTargetKeys) : selectedLifecycleStats,
|
|
6649
|
+
[gridEditMode, gridTargetKeys, computeLifecycleStatsForKeys, selectedLifecycleStats]
|
|
6650
|
+
);
|
|
4781
6651
|
const handleOpenConfirmModal = () => {
|
|
4782
6652
|
if (!selectedAttribute) {
|
|
4783
6653
|
toggleNotification({
|
|
@@ -4786,13 +6656,30 @@ const BulkUpdater = () => {
|
|
|
4786
6656
|
});
|
|
4787
6657
|
return;
|
|
4788
6658
|
}
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
6659
|
+
if (gridEditMode) {
|
|
6660
|
+
if (gridSerialized.targets.length === 0) {
|
|
6661
|
+
toggleNotification({
|
|
6662
|
+
type: "warning",
|
|
6663
|
+
message: "Please edit at least one selected cell or block in the grid before updating"
|
|
6664
|
+
});
|
|
6665
|
+
return;
|
|
6666
|
+
}
|
|
6667
|
+
if (gridSerialized.hasValidationErrors) {
|
|
6668
|
+
toggleNotification({
|
|
6669
|
+
type: "danger",
|
|
6670
|
+
message: "Please resolve inline validation errors highlighted in red before updating"
|
|
6671
|
+
});
|
|
6672
|
+
return;
|
|
6673
|
+
}
|
|
6674
|
+
} else {
|
|
6675
|
+
const totalSelected = Object.values(selectedEntries).filter(Boolean).length;
|
|
6676
|
+
if (totalSelected === 0) {
|
|
6677
|
+
toggleNotification({
|
|
6678
|
+
type: "warning",
|
|
6679
|
+
message: "Please select at least one collection type or entry to update"
|
|
6680
|
+
});
|
|
6681
|
+
return;
|
|
6682
|
+
}
|
|
4796
6683
|
}
|
|
4797
6684
|
setPublishStrategy("safe");
|
|
4798
6685
|
setUnreviewedConsent(false);
|
|
@@ -4806,44 +6693,63 @@ const BulkUpdater = () => {
|
|
|
4806
6693
|
});
|
|
4807
6694
|
return;
|
|
4808
6695
|
}
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
if (
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
6696
|
+
let targets = [];
|
|
6697
|
+
if (gridEditMode) {
|
|
6698
|
+
if (gridSerialized.hasValidationErrors) {
|
|
6699
|
+
toggleNotification({
|
|
6700
|
+
type: "danger",
|
|
6701
|
+
message: "Please fix inline validation errors before previewing changes"
|
|
6702
|
+
});
|
|
6703
|
+
return;
|
|
6704
|
+
}
|
|
6705
|
+
targets = gridSerialized.targets;
|
|
6706
|
+
if (targets.length === 0) {
|
|
6707
|
+
toggleNotification({
|
|
6708
|
+
type: "warning",
|
|
6709
|
+
message: "Please modify and select at least one grid cell or block to preview"
|
|
6710
|
+
});
|
|
6711
|
+
return;
|
|
6712
|
+
}
|
|
6713
|
+
} else {
|
|
6714
|
+
Object.keys(selectedEntries).forEach((key) => {
|
|
6715
|
+
if (selectedEntries[key]) {
|
|
6716
|
+
const parts = key.split(KEY_SEP);
|
|
6717
|
+
if (parts.length === 2) {
|
|
6718
|
+
const colUid = parts[0];
|
|
6719
|
+
const docId = parts[1];
|
|
6720
|
+
const targetObj = { uid: colUid, documentId: docId };
|
|
6721
|
+
if (selectedDzBlocks[key] && selectedDzBlocks[key].length > 0) {
|
|
6722
|
+
targetObj.dynamicZoneIndexes = selectedDzBlocks[key];
|
|
6723
|
+
}
|
|
6724
|
+
const colPage = collectionPages[colUid];
|
|
6725
|
+
const cachedEntry = colPage?.entries?.find((e) => e.documentId === docId);
|
|
6726
|
+
if (cachedEntry) {
|
|
6727
|
+
if (cachedEntry.status) targetObj.status = cachedEntry.status;
|
|
6728
|
+
if (cachedEntry.publishedAt) targetObj.publishedAt = cachedEntry.publishedAt;
|
|
6729
|
+
if (cachedEntry.locale) targetObj.locale = cachedEntry.locale;
|
|
6730
|
+
}
|
|
6731
|
+
targets.push(targetObj);
|
|
4826
6732
|
}
|
|
4827
|
-
targets.push(targetObj);
|
|
4828
6733
|
}
|
|
4829
|
-
}
|
|
4830
|
-
});
|
|
4831
|
-
if (targets.length === 0) {
|
|
4832
|
-
toggleNotification({
|
|
4833
|
-
type: "warning",
|
|
4834
|
-
message: "Please select at least one collection type or entry to preview"
|
|
4835
6734
|
});
|
|
4836
|
-
|
|
6735
|
+
if (targets.length === 0) {
|
|
6736
|
+
toggleNotification({
|
|
6737
|
+
type: "warning",
|
|
6738
|
+
message: "Please select at least one collection type or entry to preview"
|
|
6739
|
+
});
|
|
6740
|
+
return;
|
|
6741
|
+
}
|
|
4837
6742
|
}
|
|
4838
6743
|
setShowPreviewModal(true);
|
|
4839
6744
|
setPreviewLoading(true);
|
|
4840
6745
|
try {
|
|
4841
6746
|
const res = await post("/bulk-updater/preview", {
|
|
4842
6747
|
attribute: selectedAttribute,
|
|
4843
|
-
value: attributeValue,
|
|
6748
|
+
value: gridEditMode ? "" : attributeValue,
|
|
6749
|
+
editMode: gridEditMode ? "grid" : "common",
|
|
4844
6750
|
selectedEntries: targets,
|
|
4845
|
-
isRegex: useRegex,
|
|
4846
|
-
regexPattern,
|
|
6751
|
+
isRegex: gridEditMode ? false : useRegex,
|
|
6752
|
+
regexPattern: gridEditMode ? "" : regexPattern,
|
|
4847
6753
|
publishOnApproval
|
|
4848
6754
|
});
|
|
4849
6755
|
if (res.data && res.data.success) {
|
|
@@ -4864,28 +6770,33 @@ const BulkUpdater = () => {
|
|
|
4864
6770
|
}
|
|
4865
6771
|
};
|
|
4866
6772
|
const executeBatchWithMode = async (executionMode, forceImmediate = false) => {
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
const
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
if (cachedEntry
|
|
6773
|
+
let targets = [];
|
|
6774
|
+
if (gridEditMode) {
|
|
6775
|
+
targets = gridSerialized.targets;
|
|
6776
|
+
} else {
|
|
6777
|
+
Object.keys(selectedEntries).forEach((key) => {
|
|
6778
|
+
if (selectedEntries[key]) {
|
|
6779
|
+
const parts = key.split(KEY_SEP);
|
|
6780
|
+
if (parts.length === 2) {
|
|
6781
|
+
const colUid = parts[0];
|
|
6782
|
+
const docId = parts[1];
|
|
6783
|
+
const targetObj = { uid: colUid, documentId: docId };
|
|
6784
|
+
if (selectedDzBlocks[key] && selectedDzBlocks[key].length > 0) {
|
|
6785
|
+
targetObj.dynamicZoneIndexes = selectedDzBlocks[key];
|
|
6786
|
+
}
|
|
6787
|
+
const colPage = collectionPages[colUid];
|
|
6788
|
+
const cachedEntry = colPage?.entries?.find((e) => e.documentId === docId);
|
|
6789
|
+
if (cachedEntry) {
|
|
6790
|
+
if (cachedEntry.status) targetObj.status = cachedEntry.status;
|
|
6791
|
+
if (cachedEntry.publishedAt) targetObj.publishedAt = cachedEntry.publishedAt;
|
|
6792
|
+
if (cachedEntry.locale) targetObj.locale = cachedEntry.locale;
|
|
6793
|
+
}
|
|
6794
|
+
targets.push(targetObj);
|
|
4884
6795
|
}
|
|
4885
|
-
targets.push(targetObj);
|
|
4886
6796
|
}
|
|
4887
|
-
}
|
|
4888
|
-
}
|
|
6797
|
+
});
|
|
6798
|
+
}
|
|
6799
|
+
const displaySummaryVal = gridEditMode ? `Grid Editing (${gridSerialized.totalEditCount} edits across ${targets.length} records)` : attributeValue;
|
|
4889
6800
|
try {
|
|
4890
6801
|
setUpdating(true);
|
|
4891
6802
|
setShowConfirmModal(false);
|
|
@@ -4900,7 +6811,7 @@ const BulkUpdater = () => {
|
|
|
4900
6811
|
status: "processing",
|
|
4901
6812
|
executionMode,
|
|
4902
6813
|
attribute: selectedAttribute,
|
|
4903
|
-
value:
|
|
6814
|
+
value: displaySummaryVal,
|
|
4904
6815
|
totalTargets: targets.length,
|
|
4905
6816
|
processedCount: 0,
|
|
4906
6817
|
updatedCount: 0,
|
|
@@ -4915,10 +6826,11 @@ const BulkUpdater = () => {
|
|
|
4915
6826
|
});
|
|
4916
6827
|
const payload = {
|
|
4917
6828
|
attribute: selectedAttribute,
|
|
4918
|
-
value: attributeValue,
|
|
6829
|
+
value: gridEditMode ? "" : attributeValue,
|
|
6830
|
+
editMode: gridEditMode ? "grid" : "common",
|
|
4919
6831
|
selectedEntries: targets,
|
|
4920
|
-
isRegex: useRegex,
|
|
4921
|
-
regexPattern,
|
|
6832
|
+
isRegex: gridEditMode ? false : useRegex,
|
|
6833
|
+
regexPattern: gridEditMode ? "" : regexPattern,
|
|
4922
6834
|
executionMode,
|
|
4923
6835
|
makerNotes: makerNotesInput,
|
|
4924
6836
|
forceImmediate,
|
|
@@ -4930,11 +6842,12 @@ const BulkUpdater = () => {
|
|
|
4930
6842
|
const res = await post("/bulk-updater/batch-update", payload);
|
|
4931
6843
|
setIsSubmittingBatch(false);
|
|
4932
6844
|
if (res.data && res.data.success) {
|
|
4933
|
-
setSelectedEntries({});
|
|
4934
|
-
setSelectedDzBlocks({});
|
|
4935
6845
|
const finalBatchId = res.data.batchId;
|
|
4936
6846
|
setDashboardBatchId(finalBatchId);
|
|
4937
6847
|
if (res.data.pending) {
|
|
6848
|
+
setSelectedEntries({});
|
|
6849
|
+
setSelectedDzBlocks({});
|
|
6850
|
+
if (gridEditMode) setGridEdits({});
|
|
4938
6851
|
setDashboardJob({
|
|
4939
6852
|
id: finalBatchId,
|
|
4940
6853
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -4942,7 +6855,7 @@ const BulkUpdater = () => {
|
|
|
4942
6855
|
executionMode,
|
|
4943
6856
|
scheduledFor: res.data.scheduledFor,
|
|
4944
6857
|
attribute: selectedAttribute,
|
|
4945
|
-
value:
|
|
6858
|
+
value: displaySummaryVal,
|
|
4946
6859
|
totalTargets: targets.length,
|
|
4947
6860
|
processedCount: 0,
|
|
4948
6861
|
updatedCount: 0,
|
|
@@ -4960,7 +6873,31 @@ const BulkUpdater = () => {
|
|
|
4960
6873
|
});
|
|
4961
6874
|
await fetchPendingBatches();
|
|
4962
6875
|
} else {
|
|
4963
|
-
|
|
6876
|
+
const resultList = res.data.results || [];
|
|
6877
|
+
if (gridEditMode) {
|
|
6878
|
+
const failedKeys = new Set(
|
|
6879
|
+
resultList.filter((r) => r.status === "error" && r.uid && r.documentId).map((r) => `${r.uid}${KEY_SEP}${r.documentId}`)
|
|
6880
|
+
);
|
|
6881
|
+
setGridEdits((prev) => {
|
|
6882
|
+
const next = {};
|
|
6883
|
+
for (const k of Object.keys(prev)) {
|
|
6884
|
+
if (failedKeys.has(k)) next[k] = prev[k];
|
|
6885
|
+
}
|
|
6886
|
+
return next;
|
|
6887
|
+
});
|
|
6888
|
+
setSelectedEntries((prev) => {
|
|
6889
|
+
const next = {};
|
|
6890
|
+
for (const k of Object.keys(prev)) {
|
|
6891
|
+
if (failedKeys.has(k) && prev[k]) next[k] = true;
|
|
6892
|
+
}
|
|
6893
|
+
return next;
|
|
6894
|
+
});
|
|
6895
|
+
setSelectedDzBlocks({});
|
|
6896
|
+
} else {
|
|
6897
|
+
setSelectedEntries({});
|
|
6898
|
+
setSelectedDzBlocks({});
|
|
6899
|
+
}
|
|
6900
|
+
setLastResults(resultList);
|
|
4964
6901
|
setUpdateSummary({
|
|
4965
6902
|
updatedCount: res.data.updatedCount || 0,
|
|
4966
6903
|
skippedCount: res.data.skippedCount || 0,
|
|
@@ -4973,15 +6910,15 @@ const BulkUpdater = () => {
|
|
|
4973
6910
|
status: res.data.status || "successful",
|
|
4974
6911
|
executionMode: "immediate",
|
|
4975
6912
|
attribute: selectedAttribute,
|
|
4976
|
-
value:
|
|
6913
|
+
value: res.data.value || displaySummaryVal,
|
|
4977
6914
|
totalTargets: res.data.totalTargets || targets.length,
|
|
4978
|
-
processedCount:
|
|
6915
|
+
processedCount: resultList.length || targets.length,
|
|
4979
6916
|
updatedCount: res.data.updatedCount || 0,
|
|
4980
6917
|
skippedCount: res.data.skippedCount || 0,
|
|
4981
6918
|
failedCount: res.data.failedCount || 0,
|
|
4982
6919
|
isLive: res.data.isLive !== false && res.data.updatedCount > 0,
|
|
4983
6920
|
publishOnApproval,
|
|
4984
|
-
results:
|
|
6921
|
+
results: resultList
|
|
4985
6922
|
});
|
|
4986
6923
|
toggleNotification({
|
|
4987
6924
|
type: "success",
|
|
@@ -5834,6 +7771,7 @@ const BulkUpdater = () => {
|
|
|
5834
7771
|
Checkbox,
|
|
5835
7772
|
{
|
|
5836
7773
|
checked: useRegex,
|
|
7774
|
+
disabled: gridEditMode,
|
|
5837
7775
|
onCheckedChange: (checked) => setUseRegex(Boolean(checked)),
|
|
5838
7776
|
children: /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: "Enable Regex Search & Replace" })
|
|
5839
7777
|
}
|
|
@@ -5841,10 +7779,10 @@ const BulkUpdater = () => {
|
|
|
5841
7779
|
/* @__PURE__ */ jsx(
|
|
5842
7780
|
Badge,
|
|
5843
7781
|
{
|
|
5844
|
-
backgroundColor: useRegex ? "secondary100" : "neutral200",
|
|
5845
|
-
textColor: useRegex ? "secondary700" : "neutral600",
|
|
7782
|
+
backgroundColor: gridEditMode ? "neutral200" : useRegex ? "secondary100" : "neutral200",
|
|
7783
|
+
textColor: gridEditMode ? "neutral600" : useRegex ? "secondary700" : "neutral600",
|
|
5846
7784
|
size: "S",
|
|
5847
|
-
children: useRegex ? "REGEX SEARCH ACTIVE" : "REGEX OFF"
|
|
7785
|
+
children: gridEditMode ? "DISABLED IN GRID EDIT" : useRegex ? "REGEX SEARCH ACTIVE" : "REGEX OFF"
|
|
5848
7786
|
}
|
|
5849
7787
|
)
|
|
5850
7788
|
] }),
|
|
@@ -6269,6 +8207,72 @@ const BulkUpdater = () => {
|
|
|
6269
8207
|
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: col.isSingleType ? "1 single entry" : isFilterActive ? `${totalEntries} matching entries in DB` : `${totalEntries} entries` })
|
|
6270
8208
|
] })
|
|
6271
8209
|
] }),
|
|
8210
|
+
gridEditMode && /* @__PURE__ */ jsx(
|
|
8211
|
+
Box,
|
|
8212
|
+
{
|
|
8213
|
+
padding: 3,
|
|
8214
|
+
marginBottom: 3,
|
|
8215
|
+
background: "primary100",
|
|
8216
|
+
hasRadius: true,
|
|
8217
|
+
style: { border: "1px solid #d9d8ff" },
|
|
8218
|
+
children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", wrap: "wrap", gap: 2, children: [
|
|
8219
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", wrap: "wrap", children: [
|
|
8220
|
+
/* @__PURE__ */ jsx(Badge, { backgroundColor: "primary600", textColor: "neutral0", children: "GRID EDITING MODE" }),
|
|
8221
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "bold", textColor: "primary700", children: selectedAttribute ? `Editing "${selectedAttribute}" directly per record & component block` : 'Select an "Attribute to Update" below to enable inline cell editors' }),
|
|
8222
|
+
/* @__PURE__ */ jsxs(Badge, { backgroundColor: "neutral0", textColor: "primary700", children: [
|
|
8223
|
+
totalDirtyCellsCount,
|
|
8224
|
+
" edit",
|
|
8225
|
+
totalDirtyCellsCount === 1 ? "" : "s",
|
|
8226
|
+
" across ",
|
|
8227
|
+
totalDirtyRecordsCount,
|
|
8228
|
+
" record",
|
|
8229
|
+
totalDirtyRecordsCount === 1 ? "" : "s"
|
|
8230
|
+
] })
|
|
8231
|
+
] }),
|
|
8232
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", wrap: "wrap", children: [
|
|
8233
|
+
(activeAttrMeta?.rootType === "dynamiczone" || activeAttrMeta?.rootRepeatable) && visibleEntries.length > 0 && /* @__PURE__ */ jsx(
|
|
8234
|
+
Button,
|
|
8235
|
+
{
|
|
8236
|
+
variant: "secondary",
|
|
8237
|
+
size: "S",
|
|
8238
|
+
onClick: () => {
|
|
8239
|
+
const allVisibleKeys = visibleEntries.map((e) => `${col.uid}${KEY_SEP}${e.documentId}`);
|
|
8240
|
+
const anyCollapsed = allVisibleKeys.some((k) => !expandedDzEntries[k]);
|
|
8241
|
+
setExpandedDzEntries((prev) => {
|
|
8242
|
+
const next = { ...prev };
|
|
8243
|
+
allVisibleKeys.forEach((k) => {
|
|
8244
|
+
next[k] = anyCollapsed;
|
|
8245
|
+
});
|
|
8246
|
+
return next;
|
|
8247
|
+
});
|
|
8248
|
+
},
|
|
8249
|
+
children: visibleEntries.some((e) => !expandedDzEntries[`${col.uid}${KEY_SEP}${e.documentId}`]) ? "Expand All Blocks" : "Collapse All Blocks"
|
|
8250
|
+
}
|
|
8251
|
+
),
|
|
8252
|
+
/* @__PURE__ */ jsx(
|
|
8253
|
+
Button,
|
|
8254
|
+
{
|
|
8255
|
+
variant: gridFilterModifiedOnly ? "default" : "tertiary",
|
|
8256
|
+
size: "S",
|
|
8257
|
+
onClick: () => setGridFilterModifiedOnly((v) => !v),
|
|
8258
|
+
disabled: totalDirtyRecordsCount === 0 && !gridFilterModifiedOnly,
|
|
8259
|
+
children: gridFilterModifiedOnly ? "Showing Modified Only" : "Filter: Modified Only"
|
|
8260
|
+
}
|
|
8261
|
+
),
|
|
8262
|
+
/* @__PURE__ */ jsx(
|
|
8263
|
+
Button,
|
|
8264
|
+
{
|
|
8265
|
+
variant: "danger-light",
|
|
8266
|
+
size: "S",
|
|
8267
|
+
disabled: totalDirtyCellsCount === 0,
|
|
8268
|
+
onClick: () => setGridEdits({}),
|
|
8269
|
+
children: "Discard All Edits"
|
|
8270
|
+
}
|
|
8271
|
+
)
|
|
8272
|
+
] })
|
|
8273
|
+
] })
|
|
8274
|
+
}
|
|
8275
|
+
),
|
|
6272
8276
|
/* @__PURE__ */ jsx(Box, { className: "bulk-updater-table-container", style: { width: "100%", maxWidth: "100%", minWidth: 0, overflowX: "auto" }, children: /* @__PURE__ */ jsxs(Table, { colCount: activeColumns.length, rowCount: visibleEntries.length + 1, style: { width: "100%" }, children: [
|
|
6273
8277
|
/* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsx(Tr, { children: activeColumns.map(
|
|
6274
8278
|
(colDef) => renderHeaderCell(colDef, col, currentSort, selectedAttribute, searchAttribute, handleHeaderSortClick)
|
|
@@ -6285,12 +8289,27 @@ const BulkUpdater = () => {
|
|
|
6285
8289
|
const dzFields = Object.keys(entry).filter(
|
|
6286
8290
|
(k) => Array.isArray(entry[k]) && entry[k].length > 0 && entry[k].some((item) => item && item.__component)
|
|
6287
8291
|
);
|
|
8292
|
+
const selectedRootKey = selectedAttribute ? selectedAttribute.split("[")[0].split(".")[0] : "";
|
|
8293
|
+
const expandableArrayFields = gridEditMode && selectedRootKey && activeAttrMeta?.rootRepeatable && !dzFields.includes(selectedRootKey) && Array.isArray(entry[selectedRootKey]) && entry[selectedRootKey].length > 0 ? [...dzFields, selectedRootKey] : dzFields;
|
|
8294
|
+
const recordEdits = gridEdits[key];
|
|
8295
|
+
const gridCtx = gridEditMode ? {
|
|
8296
|
+
gridEditMode: true,
|
|
8297
|
+
selectedAttrMeta: activeAttrMeta,
|
|
8298
|
+
recordEdits,
|
|
8299
|
+
relationOptions,
|
|
8300
|
+
relationOptionsLoading,
|
|
8301
|
+
relationIsMulti: Boolean(relationsMeta[selectedAttribute]?.isMulti),
|
|
8302
|
+
validationRules,
|
|
8303
|
+
onCommitEdit: handleGridCellCommit,
|
|
8304
|
+
onResetEdit: handleGridCellReset
|
|
8305
|
+
} : void 0;
|
|
8306
|
+
const rowOccs = gridEditMode && isDzExpanded && selectedAttribute ? enumerateClientOccurrences(entry, selectedAttribute, col?.attributes, activeAttrMeta) : [];
|
|
6288
8307
|
return /* @__PURE__ */ jsxs(React__default.Fragment, { children: [
|
|
6289
8308
|
/* @__PURE__ */ jsx(
|
|
6290
8309
|
Tr,
|
|
6291
8310
|
{
|
|
6292
8311
|
style: {
|
|
6293
|
-
backgroundColor: isSelected ? "rgba(73, 69, 255, 0.14)" : isMatch ? "rgba(46, 213, 115, 0.08)" : void 0,
|
|
8312
|
+
backgroundColor: recordEdits ? "rgba(73, 69, 255, 0.10)" : isSelected ? "rgba(73, 69, 255, 0.14)" : isMatch ? "rgba(46, 213, 115, 0.08)" : void 0,
|
|
6294
8313
|
boxShadow: isSelected ? "inset 3px 0 0 0 #4945ff" : isMatch ? "inset 3px 0 0 0 #2ed573" : void 0
|
|
6295
8314
|
},
|
|
6296
8315
|
children: activeColumns.map((colDef) => /* @__PURE__ */ jsx(Td, { children: renderCellContent(
|
|
@@ -6306,97 +8325,47 @@ const BulkUpdater = () => {
|
|
|
6306
8325
|
pendingBatches,
|
|
6307
8326
|
isDzExpanded,
|
|
6308
8327
|
onToggleExpandDz,
|
|
6309
|
-
filterQuery
|
|
8328
|
+
filterQuery,
|
|
8329
|
+
gridCtx
|
|
6310
8330
|
) }, colDef.key))
|
|
6311
8331
|
}
|
|
6312
8332
|
),
|
|
6313
|
-
isDzExpanded &&
|
|
6314
|
-
const
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
if (!targetParsed.subPath) return true;
|
|
6318
|
-
const scopedPath = `${dzKey}[${blockItem?.__component}].${targetParsed.subPath}`;
|
|
6319
|
-
const componentSupports = (col?.attributes || attributes || []).includes(scopedPath);
|
|
6320
|
-
return componentSupports || getNestedValue(blockItem, targetParsed.subPath) !== void 0;
|
|
6321
|
-
};
|
|
6322
|
-
const allApplicableIndexes = blocks.map((_, i) => i).filter((i) => isBlockApplicable(blocks[i]));
|
|
6323
|
-
return /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(Td, { colSpan: activeColumns.length, style: { padding: "12px 16px", backgroundColor: "rgba(73, 69, 255, 0.02)", borderBottom: "2px solid rgba(73, 69, 255, 0.15)" }, children: /* @__PURE__ */ jsxs(
|
|
6324
|
-
Box,
|
|
8333
|
+
isDzExpanded && expandableArrayFields.map((dzKey) => {
|
|
8334
|
+
const drawerOccurrences = gridEditMode && selectedAttribute ? rowOccs : enumerateClientOccurrences(entry, selectedAttribute, col?.attributes, activeAttrMeta);
|
|
8335
|
+
return /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(
|
|
8336
|
+
Td,
|
|
6325
8337
|
{
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
] }) }),
|
|
6356
|
-
/* @__PURE__ */ jsx(Tbody, { children: blocks.map((block, bIdx) => {
|
|
6357
|
-
const compUid = block.__component;
|
|
6358
|
-
const compLabel = formatComponentName(compUid);
|
|
6359
|
-
const scopedPath = `${dzKey}[${compUid}].${targetParsed.subPath}`;
|
|
6360
|
-
const componentSupports = (col?.attributes || attributes || []).includes(scopedPath);
|
|
6361
|
-
const blockVal = targetParsed.subPath ? getNestedValue(block, targetParsed.subPath) : void 0;
|
|
6362
|
-
const hasTargetAttr = componentSupports || blockVal !== void 0;
|
|
6363
|
-
const isBlockChecked = hasTargetAttr && isSelected && (selectedDzBlocks[key] !== void 0 ? selectedDzBlocks[key].includes(bIdx) : true);
|
|
6364
|
-
return /* @__PURE__ */ jsxs(
|
|
6365
|
-
Tr,
|
|
6366
|
-
{
|
|
6367
|
-
style: {
|
|
6368
|
-
backgroundColor: isBlockChecked ? "rgba(73, 69, 255, 0.08)" : void 0
|
|
6369
|
-
},
|
|
6370
|
-
children: [
|
|
6371
|
-
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(
|
|
6372
|
-
Checkbox,
|
|
6373
|
-
{
|
|
6374
|
-
checked: isBlockChecked,
|
|
6375
|
-
disabled: !hasTargetAttr,
|
|
6376
|
-
onCheckedChange: () => {
|
|
6377
|
-
toggleDzBlock(col.uid, entry.documentId, bIdx, allApplicableIndexes);
|
|
6378
|
-
}
|
|
6379
|
-
}
|
|
6380
|
-
) }),
|
|
6381
|
-
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Typography, { variant: "pi", fontWeight: "bold", children: [
|
|
6382
|
-
"#",
|
|
6383
|
-
bIdx
|
|
6384
|
-
] }) }),
|
|
6385
|
-
/* @__PURE__ */ jsxs(Td, { children: [
|
|
6386
|
-
/* @__PURE__ */ jsx(Badge, { backgroundColor: "neutral150", textColor: "neutral800", children: compLabel }),
|
|
6387
|
-
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", display: "block", style: { fontSize: "0.68rem", marginTop: 2 }, children: compUid })
|
|
6388
|
-
] }),
|
|
6389
|
-
/* @__PURE__ */ jsx(Td, { children: hasTargetAttr ? /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", textColor: "primary700", children: formatDisplayValue(blockVal) }) : /* @__PURE__ */ jsx(Badge, { backgroundColor: "neutral100", textColor: "neutral500", children: "Does not contain attribute" }) }),
|
|
6390
|
-
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", style: { maxWidth: 300, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: block.title || block.name || block.heading || block.body || Object.keys(block).filter((k) => !k.startsWith("_") && k !== "id").slice(0, 3).map((k) => `${k}: ${formatDisplayValue(block[k])}`).join(", ") || "-" }) })
|
|
6391
|
-
]
|
|
6392
|
-
},
|
|
6393
|
-
bIdx
|
|
6394
|
-
);
|
|
6395
|
-
}) })
|
|
6396
|
-
] })
|
|
6397
|
-
]
|
|
8338
|
+
colSpan: activeColumns.length,
|
|
8339
|
+
style: {
|
|
8340
|
+
padding: "12px 16px",
|
|
8341
|
+
backgroundColor: "rgba(73, 69, 255, 0.02)",
|
|
8342
|
+
borderBottom: "2px solid rgba(73, 69, 255, 0.15)"
|
|
8343
|
+
},
|
|
8344
|
+
children: /* @__PURE__ */ jsx(
|
|
8345
|
+
ComponentOccurrencesDrawer,
|
|
8346
|
+
{
|
|
8347
|
+
colUid: col.uid,
|
|
8348
|
+
rootKey: dzKey,
|
|
8349
|
+
entry,
|
|
8350
|
+
selectedAttribute,
|
|
8351
|
+
attrMeta: activeAttrMeta,
|
|
8352
|
+
colAttributes: col?.attributes || attributes || [],
|
|
8353
|
+
gridEditMode,
|
|
8354
|
+
isSelected,
|
|
8355
|
+
selectedDzBlocks: selectedDzBlocks[key],
|
|
8356
|
+
occurrences: drawerOccurrences,
|
|
8357
|
+
recordEdits,
|
|
8358
|
+
relationOptions,
|
|
8359
|
+
relationOptionsLoading,
|
|
8360
|
+
relationIsMulti: Boolean(relationsMeta[selectedAttribute]?.isMulti),
|
|
8361
|
+
validationRules,
|
|
8362
|
+
onToggleDzBlock: toggleDzBlock,
|
|
8363
|
+
onCommitEdit: handleGridCellCommit,
|
|
8364
|
+
onResetEdit: handleGridCellReset
|
|
8365
|
+
}
|
|
8366
|
+
)
|
|
6398
8367
|
}
|
|
6399
|
-
) }
|
|
8368
|
+
) }, `${key}-dz-${dzKey}`);
|
|
6400
8369
|
})
|
|
6401
8370
|
] }, key);
|
|
6402
8371
|
}) })
|
|
@@ -6495,10 +8464,38 @@ const BulkUpdater = () => {
|
|
|
6495
8464
|
marginBottom: 6,
|
|
6496
8465
|
style: { width: "100%", maxWidth: "100%", minWidth: 0, boxSizing: "border-box" },
|
|
6497
8466
|
children: [
|
|
6498
|
-
/* @__PURE__ */
|
|
6499
|
-
/* @__PURE__ */
|
|
6500
|
-
|
|
6501
|
-
|
|
8467
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 4, wrap: "wrap", gap: 3, children: [
|
|
8468
|
+
/* @__PURE__ */ jsxs(Box, { children: [
|
|
8469
|
+
/* @__PURE__ */ jsx(Typography, { variant: "delta", tag: "h2", fontWeight: "semiBold", children: "2. Configure Attribute Update" }),
|
|
8470
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: "Select the target attribute to update and either apply a common value or enable inline Grid Editing." })
|
|
8471
|
+
] }),
|
|
8472
|
+
/* @__PURE__ */ jsx(Flex, { gap: 3, alignItems: "center", wrap: "wrap", children: /* @__PURE__ */ jsx(
|
|
8473
|
+
Box,
|
|
8474
|
+
{
|
|
8475
|
+
padding: 2,
|
|
8476
|
+
paddingLeft: 3,
|
|
8477
|
+
paddingRight: 3,
|
|
8478
|
+
background: gridEditMode ? "primary100" : "neutral100",
|
|
8479
|
+
hasRadius: true,
|
|
8480
|
+
style: { border: gridEditMode ? "1px solid #4945ff" : "1px solid #eaeaef" },
|
|
8481
|
+
children: /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
|
|
8482
|
+
/* @__PURE__ */ jsx(
|
|
8483
|
+
Checkbox,
|
|
8484
|
+
{
|
|
8485
|
+
checked: gridEditMode,
|
|
8486
|
+
onCheckedChange: (checked) => handleToggleGridEditMode(Boolean(checked)),
|
|
8487
|
+
children: /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: gridEditMode ? "primary700" : "neutral800", children: "Edit Values in Grid" })
|
|
8488
|
+
}
|
|
8489
|
+
),
|
|
8490
|
+
gridEditMode && /* @__PURE__ */ jsxs(Badge, { backgroundColor: "primary600", textColor: "neutral0", size: "S", children: [
|
|
8491
|
+
"ON (",
|
|
8492
|
+
gridSerialized.totalEditCount,
|
|
8493
|
+
" edits)"
|
|
8494
|
+
] })
|
|
8495
|
+
] })
|
|
8496
|
+
}
|
|
8497
|
+
) })
|
|
8498
|
+
] }),
|
|
6502
8499
|
/* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "flex-end", wrap: "wrap", children: [
|
|
6503
8500
|
/* @__PURE__ */ jsx(Box, { style: { width: 280, minWidth: 230 }, children: /* @__PURE__ */ jsxs(Field.Root, { children: [
|
|
6504
8501
|
/* @__PURE__ */ jsx(Field.Label, { children: "Attribute to Update" }),
|
|
@@ -6525,7 +8522,35 @@ const BulkUpdater = () => {
|
|
|
6525
8522
|
`update-attr-${selectedCollectionUid}`
|
|
6526
8523
|
)
|
|
6527
8524
|
] }) }),
|
|
6528
|
-
/* @__PURE__ */ jsx(Box, { style: { flex: 1, minWidth: 340 }, children:
|
|
8525
|
+
/* @__PURE__ */ jsx(Box, { style: { flex: 1, minWidth: 340 }, children: gridEditMode ? /* @__PURE__ */ jsx(
|
|
8526
|
+
Box,
|
|
8527
|
+
{
|
|
8528
|
+
padding: 3,
|
|
8529
|
+
background: "primary100",
|
|
8530
|
+
hasRadius: true,
|
|
8531
|
+
style: { border: "1px solid #d9d8ff" },
|
|
8532
|
+
children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", wrap: "wrap", gap: 2, children: [
|
|
8533
|
+
/* @__PURE__ */ jsxs(Box, { children: [
|
|
8534
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "bold", textColor: "primary700", display: "block", children: "Common value input hidden — Grid Editing Mode active" }),
|
|
8535
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral700", children: gridSerialized.targets.length > 0 ? `Ready: ${gridSerialized.totalEditCount} edited field/block value(s) across ${gridSerialized.targets.length} selected record(s).` : "Edit cell values directly in the table above (or expand component blocks) to queue heterogeneous updates." }),
|
|
8536
|
+
gridSerialized.hasValidationErrors && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger700", fontWeight: "bold", display: "block", children: "⚠️ Resolve inline red validation errors before previewing or updating." })
|
|
8537
|
+
] }),
|
|
8538
|
+
totalDirtyCellsCount > 0 && /* @__PURE__ */ jsxs(
|
|
8539
|
+
Button,
|
|
8540
|
+
{
|
|
8541
|
+
variant: "danger-light",
|
|
8542
|
+
size: "S",
|
|
8543
|
+
onClick: () => setGridEdits({}),
|
|
8544
|
+
children: [
|
|
8545
|
+
"Discard Edits (",
|
|
8546
|
+
totalDirtyCellsCount,
|
|
8547
|
+
")"
|
|
8548
|
+
]
|
|
8549
|
+
}
|
|
8550
|
+
)
|
|
8551
|
+
] })
|
|
8552
|
+
}
|
|
8553
|
+
) : relationsMeta[selectedAttribute] ? /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 1, style: { width: "100%" }, children: [
|
|
6529
8554
|
/* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", wrap: "wrap", children: [
|
|
6530
8555
|
/* @__PURE__ */ jsxs(Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral700", children: [
|
|
6531
8556
|
"Target ",
|
|
@@ -6610,10 +8635,10 @@ const BulkUpdater = () => {
|
|
|
6610
8635
|
size: "L",
|
|
6611
8636
|
onClick: handleOpenPreviewModal,
|
|
6612
8637
|
loading: previewLoading,
|
|
6613
|
-
disabled: loading ||
|
|
8638
|
+
disabled: loading || !selectedAttribute || !selectedAttribute.trim() || (gridEditMode ? gridSerialized.targets.length === 0 || gridSerialized.hasValidationErrors : totalSelectedCount === 0),
|
|
6614
8639
|
children: [
|
|
6615
8640
|
"Preview Changes (",
|
|
6616
|
-
totalSelectedCount,
|
|
8641
|
+
gridEditMode ? gridSerialized.targets.length : totalSelectedCount,
|
|
6617
8642
|
")"
|
|
6618
8643
|
]
|
|
6619
8644
|
}
|
|
@@ -6626,10 +8651,10 @@ const BulkUpdater = () => {
|
|
|
6626
8651
|
size: "L",
|
|
6627
8652
|
onClick: handleOpenConfirmModal,
|
|
6628
8653
|
loading: updating,
|
|
6629
|
-
disabled: loading ||
|
|
8654
|
+
disabled: loading || !selectedAttribute || !selectedAttribute.trim() || (gridEditMode ? gridSerialized.targets.length === 0 || gridSerialized.hasValidationErrors : totalSelectedCount === 0),
|
|
6630
8655
|
children: [
|
|
6631
8656
|
"Update Selected (",
|
|
6632
|
-
totalSelectedCount,
|
|
8657
|
+
gridEditMode ? gridSerialized.targets.length : totalSelectedCount,
|
|
6633
8658
|
")"
|
|
6634
8659
|
]
|
|
6635
8660
|
}
|
|
@@ -6716,11 +8741,11 @@ const BulkUpdater = () => {
|
|
|
6716
8741
|
"Attribute: ",
|
|
6717
8742
|
selectedAttribute,
|
|
6718
8743
|
" ",
|
|
6719
|
-
|
|
8744
|
+
activeAttrMeta?.type ? `(${activeAttrMeta.type})` : ""
|
|
6720
8745
|
] }),
|
|
6721
|
-
|
|
8746
|
+
activeAttrMeta?.depth ? /* @__PURE__ */ jsxs(Badge, { backgroundColor: "neutral200", textColor: "neutral700", children: [
|
|
6722
8747
|
"Nesting Level: L",
|
|
6723
|
-
|
|
8748
|
+
activeAttrMeta.depth
|
|
6724
8749
|
] }) : null,
|
|
6725
8750
|
selectedCol.draftAndPublish ? /* @__PURE__ */ jsx(Badge, { backgroundColor: "success100", textColor: "success700", children: "Draft & Publish Enabled" }) : /* @__PURE__ */ jsx(Badge, { backgroundColor: "warning100", textColor: "warning700", children: "Direct Publish Only" })
|
|
6726
8751
|
] }) }) })
|
|
@@ -7158,7 +9183,15 @@ const BulkUpdater = () => {
|
|
|
7158
9183
|
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Previous Value" }) }),
|
|
7159
9184
|
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Applied Value" }) })
|
|
7160
9185
|
] }) }),
|
|
7161
|
-
/* @__PURE__ */ jsx(Tbody, { children: rec.diffs.
|
|
9186
|
+
/* @__PURE__ */ jsx(Tbody, { children: rec.diffs.flatMap(
|
|
9187
|
+
(d) => Array.isArray(d.dynamicZoneDiffs) && d.dynamicZoneDiffs.length > 0 ? d.dynamicZoneDiffs.map((dz) => ({
|
|
9188
|
+
collectionName: d.collectionName,
|
|
9189
|
+
label: `${d.label}${dz.componentName ? ` [${dz.componentName}]` : ""}`,
|
|
9190
|
+
attribute: dz.attribute || d.attribute,
|
|
9191
|
+
oldValue: dz.oldValue,
|
|
9192
|
+
newValue: dz.newValue
|
|
9193
|
+
})) : [d]
|
|
9194
|
+
).map((d, dIdx) => /* @__PURE__ */ jsxs(Tr, { children: [
|
|
7162
9195
|
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", children: d.collectionName }) }),
|
|
7163
9196
|
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { children: d.label }) }),
|
|
7164
9197
|
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Badge, { backgroundColor: "secondary100", textColor: "secondary700", children: d.attribute || "field" }) }),
|
|
@@ -7247,7 +9280,13 @@ const BulkUpdater = () => {
|
|
|
7247
9280
|
] }),
|
|
7248
9281
|
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [
|
|
7249
9282
|
/* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", children: "Target Value:" }),
|
|
7250
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", style: { wordBreak: "break-all", maxWidth: 360 }, children:
|
|
9283
|
+
/* @__PURE__ */ jsx(Typography, { variant: "omega", style: { wordBreak: "break-all", maxWidth: 360 }, children: gridEditMode ? /* @__PURE__ */ jsxs(Badge, { backgroundColor: "secondary100", textColor: "secondary700", children: [
|
|
9284
|
+
"Grid Editing (",
|
|
9285
|
+
gridSerialized.totalEditCount,
|
|
9286
|
+
" heterogeneous edits across ",
|
|
9287
|
+
gridSerialized.targets.length,
|
|
9288
|
+
" records)"
|
|
9289
|
+
] }) : relationsMeta[selectedAttribute] ? /* @__PURE__ */ jsx("span", { children: selectedRelationDocId === "__clear__" ? /* @__PURE__ */ jsx(Badge, { backgroundColor: "danger100", textColor: "danger700", children: "Clear / Unlink Relation" }) : /* @__PURE__ */ jsxs(Badge, { backgroundColor: "secondary100", textColor: "secondary700", children: [
|
|
7251
9290
|
relationsMeta[selectedAttribute].isMulti ? `[${relationMode.toUpperCase()}] ` : "",
|
|
7252
9291
|
relationOptions.find((o) => o.documentId === selectedRelationDocId)?.label || selectedRelationDocId || "(none selected)"
|
|
7253
9292
|
] }) }) : useRegex ? /* @__PURE__ */ jsxs("span", { children: [
|
|
@@ -7272,7 +9311,7 @@ const BulkUpdater = () => {
|
|
|
7272
9311
|
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", children: [
|
|
7273
9312
|
/* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", children: "Total Selected Records:" }),
|
|
7274
9313
|
/* @__PURE__ */ jsxs(Typography, { fontWeight: "bold", textColor: "primary600", children: [
|
|
7275
|
-
totalSelectedCount,
|
|
9314
|
+
gridEditMode ? gridSerialized.targets.length : totalSelectedCount,
|
|
7276
9315
|
" records"
|
|
7277
9316
|
] })
|
|
7278
9317
|
] }),
|
|
@@ -7308,31 +9347,31 @@ const BulkUpdater = () => {
|
|
|
7308
9347
|
/* @__PURE__ */ jsxs(Box, { marginBottom: 4, padding: 3, background: "neutral100", hasRadius: true, style: { border: "1px solid rgba(120, 120, 150, 0.15)" }, children: [
|
|
7309
9348
|
/* @__PURE__ */ jsxs(Typography, { variant: "sigma", textColor: "neutral600", marginBottom: 2, display: "block", children: [
|
|
7310
9349
|
"LIFECYCLE STATUS BREAKDOWN (",
|
|
7311
|
-
totalSelectedCount,
|
|
9350
|
+
gridEditMode ? gridSerialized.targets.length : totalSelectedCount,
|
|
7312
9351
|
" Selected)"
|
|
7313
9352
|
] }),
|
|
7314
9353
|
/* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
|
|
7315
9354
|
/* @__PURE__ */ jsxs(Badge, { backgroundColor: "success100", textColor: "success700", children: [
|
|
7316
9355
|
"✓ Published / Approved: ",
|
|
7317
|
-
|
|
9356
|
+
updateModalLifecycleStats.published
|
|
7318
9357
|
] }),
|
|
7319
|
-
|
|
9358
|
+
updateModalLifecycleStats.modified > 0 && /* @__PURE__ */ jsxs(Badge, { backgroundColor: "primary100", textColor: "primary700", children: [
|
|
7320
9359
|
"📝 Modified (Unreviewed Revisions): ",
|
|
7321
|
-
|
|
9360
|
+
updateModalLifecycleStats.modified
|
|
7322
9361
|
] }),
|
|
7323
|
-
|
|
9362
|
+
updateModalLifecycleStats.draft > 0 && /* @__PURE__ */ jsxs(Badge, { backgroundColor: "neutral200", textColor: "neutral800", children: [
|
|
7324
9363
|
"📄 Draft (Never Published): ",
|
|
7325
|
-
|
|
9364
|
+
updateModalLifecycleStats.draft
|
|
7326
9365
|
] }),
|
|
7327
|
-
|
|
9366
|
+
updateModalLifecycleStats.pendingReview > 0 && /* @__PURE__ */ jsxs(Badge, { backgroundColor: "warning100", textColor: "warning700", children: [
|
|
7328
9367
|
"⏳ Pending Review: ",
|
|
7329
|
-
|
|
9368
|
+
updateModalLifecycleStats.pendingReview
|
|
7330
9369
|
] })
|
|
7331
9370
|
] })
|
|
7332
9371
|
] }),
|
|
7333
9372
|
/* @__PURE__ */ jsxs(Box, { marginBottom: 4, children: [
|
|
7334
9373
|
/* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", marginBottom: 2, display: "block", children: "COLLECTION BREAKDOWN" }),
|
|
7335
|
-
/* @__PURE__ */ jsx(Flex, { direction: "column", gap: 1, children: Object.entries(getSelectedBreakdown()).map(([name, count]) => /* @__PURE__ */ jsxs(
|
|
9374
|
+
/* @__PURE__ */ jsx(Flex, { direction: "column", gap: 1, children: Object.entries(getSelectedBreakdown(gridEditMode ? gridTargetKeys : void 0)).map(([name, count]) => /* @__PURE__ */ jsxs(
|
|
7336
9375
|
Flex,
|
|
7337
9376
|
{
|
|
7338
9377
|
justifyContent: "space-between",
|
|
@@ -7380,7 +9419,7 @@ const BulkUpdater = () => {
|
|
|
7380
9419
|
] })
|
|
7381
9420
|
}
|
|
7382
9421
|
),
|
|
7383
|
-
publishOnApproval &&
|
|
9422
|
+
publishOnApproval && updateModalLifecycleStats.unreviewedCount > 0 && /* @__PURE__ */ jsxs(
|
|
7384
9423
|
Box,
|
|
7385
9424
|
{
|
|
7386
9425
|
padding: 4,
|
|
@@ -7424,11 +9463,11 @@ const BulkUpdater = () => {
|
|
|
7424
9463
|
/* @__PURE__ */ jsx(Typography, { fontWeight: "bold", display: "block", children: "🛡️ Safe Publishing (Recommended)" }),
|
|
7425
9464
|
/* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral600", children: [
|
|
7426
9465
|
"Only publish records that are already approved & live (",
|
|
7427
|
-
|
|
9466
|
+
updateModalLifecycleStats.published,
|
|
7428
9467
|
" record",
|
|
7429
|
-
|
|
9468
|
+
updateModalLifecycleStats.published === 1 ? "" : "s",
|
|
7430
9469
|
"). The ",
|
|
7431
|
-
|
|
9470
|
+
updateModalLifecycleStats.unreviewedCount,
|
|
7432
9471
|
" unreviewed or draft record(s) will receive the bulk update in Draft mode without publishing unreviewed draft revisions to visitors."
|
|
7433
9472
|
] })
|
|
7434
9473
|
] })
|
|
@@ -7462,9 +9501,9 @@ const BulkUpdater = () => {
|
|
|
7462
9501
|
/* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "danger700", display: "block", children: "⚠️ Publish All Selected Records (Includes Unreviewed Drafts)" }),
|
|
7463
9502
|
/* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral600", children: [
|
|
7464
9503
|
"Publish all ",
|
|
7465
|
-
totalSelectedCount,
|
|
9504
|
+
gridEditMode ? gridSerialized.targets.length : totalSelectedCount,
|
|
7466
9505
|
" records live to production immediately, pushing all pending unreviewed draft edits in the ",
|
|
7467
|
-
|
|
9506
|
+
updateModalLifecycleStats.unreviewedCount,
|
|
7468
9507
|
" draft/modified record(s) live."
|
|
7469
9508
|
] })
|
|
7470
9509
|
] })
|
|
@@ -7491,7 +9530,7 @@ const BulkUpdater = () => {
|
|
|
7491
9530
|
/* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "danger700", display: "block", children: "Mandatory Risk Consent Required" }),
|
|
7492
9531
|
/* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "danger700", children: [
|
|
7493
9532
|
"I understand and explicitly consent that ",
|
|
7494
|
-
|
|
9533
|
+
updateModalLifecycleStats.unreviewedCount,
|
|
7495
9534
|
" record(s) with unreviewed draft revisions or saved draft states will be published live to production visitors."
|
|
7496
9535
|
] })
|
|
7497
9536
|
] })
|
|
@@ -7529,7 +9568,7 @@ const BulkUpdater = () => {
|
|
|
7529
9568
|
boxShadow: "0 -4px 16px rgba(0, 0, 0, 0.08)"
|
|
7530
9569
|
},
|
|
7531
9570
|
children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, style: { width: "100%" }, children: [
|
|
7532
|
-
publishOnApproval &&
|
|
9571
|
+
publishOnApproval && updateModalLifecycleStats.unreviewedCount > 0 && publishStrategy === "all" && !unreviewedConsent && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger700", fontWeight: "bold", children: "⚠️ Explicit consent is required before publishing records with unreviewed draft revisions." }),
|
|
7533
9572
|
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", gap: 3, style: { width: "100%" }, children: [
|
|
7534
9573
|
/* @__PURE__ */ jsx(Button, { variant: "tertiary", size: "M", onClick: () => setShowConfirmModal(false), children: "Cancel" }),
|
|
7535
9574
|
/* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", justifyContent: "flex-end", alignItems: "center", children: [
|
|
@@ -7540,7 +9579,7 @@ const BulkUpdater = () => {
|
|
|
7540
9579
|
size: "M",
|
|
7541
9580
|
onClick: () => executeBatchWithMode("maker_checker"),
|
|
7542
9581
|
loading: updating,
|
|
7543
|
-
disabled: updating || publishOnApproval &&
|
|
9582
|
+
disabled: updating || publishOnApproval && updateModalLifecycleStats.unreviewedCount > 0 && publishStrategy === "all" && !unreviewedConsent,
|
|
7544
9583
|
children: "Submit for Checker Approval"
|
|
7545
9584
|
}
|
|
7546
9585
|
),
|
|
@@ -7552,7 +9591,7 @@ const BulkUpdater = () => {
|
|
|
7552
9591
|
size: "M",
|
|
7553
9592
|
onClick: () => executeBatchWithMode("queue_offpeak"),
|
|
7554
9593
|
loading: updating,
|
|
7555
|
-
disabled: updating || publishOnApproval &&
|
|
9594
|
+
disabled: updating || publishOnApproval && updateModalLifecycleStats.unreviewedCount > 0 && publishStrategy === "all" && !unreviewedConsent,
|
|
7556
9595
|
children: [
|
|
7557
9596
|
"Queue for Off-Peak (",
|
|
7558
9597
|
executionWindow?.offPeakStartTime || "18:00",
|
|
@@ -7567,7 +9606,7 @@ const BulkUpdater = () => {
|
|
|
7567
9606
|
size: "S",
|
|
7568
9607
|
onClick: () => executeBatchWithMode("immediate", true),
|
|
7569
9608
|
loading: updating,
|
|
7570
|
-
disabled: updating || publishOnApproval &&
|
|
9609
|
+
disabled: updating || publishOnApproval && updateModalLifecycleStats.unreviewedCount > 0 && publishStrategy === "all" && !unreviewedConsent,
|
|
7571
9610
|
children: "Force Run Now"
|
|
7572
9611
|
}
|
|
7573
9612
|
)
|
|
@@ -7578,7 +9617,7 @@ const BulkUpdater = () => {
|
|
|
7578
9617
|
size: "M",
|
|
7579
9618
|
onClick: () => executeBatchWithMode("immediate"),
|
|
7580
9619
|
loading: updating,
|
|
7581
|
-
disabled: updating || publishOnApproval &&
|
|
9620
|
+
disabled: updating || publishOnApproval && updateModalLifecycleStats.unreviewedCount > 0 && publishStrategy === "all" && !unreviewedConsent,
|
|
7582
9621
|
children: "Confirm & Execute Now"
|
|
7583
9622
|
}
|
|
7584
9623
|
)
|
|
@@ -7867,9 +9906,10 @@ const BulkUpdater = () => {
|
|
|
7867
9906
|
loading: previewLoading,
|
|
7868
9907
|
previewData,
|
|
7869
9908
|
attribute: selectedAttribute,
|
|
9909
|
+
editMode: gridEditMode ? "grid" : "common",
|
|
7870
9910
|
publishOnApproval,
|
|
7871
9911
|
lifecycleStats: selectedLifecycleStats,
|
|
7872
|
-
targetValueDisplay: relationsMeta[selectedAttribute] ? selectedRelationDocId === "__clear__" ? "Clear / Unlink Relation" : relationOptions.find((o) => o.documentId === selectedRelationDocId)?.label || selectedRelationDocId || "(none)" : useRegex ? `Replace /${regexPattern}/g with "${attributeValue}"` : attributeValue
|
|
9912
|
+
targetValueDisplay: gridEditMode ? `Grid Editing (${gridSerialized.totalEditCount} edits across ${gridSerialized.targets.length} records)` : relationsMeta[selectedAttribute] ? selectedRelationDocId === "__clear__" ? "Clear / Unlink Relation" : relationOptions.find((o) => o.documentId === selectedRelationDocId)?.label || selectedRelationDocId || "(none)" : useRegex ? `Replace /${regexPattern}/g with "${attributeValue}"` : attributeValue
|
|
7873
9913
|
}
|
|
7874
9914
|
),
|
|
7875
9915
|
/* @__PURE__ */ jsx(
|
|
@@ -7911,4 +9951,4 @@ export {
|
|
|
7911
9951
|
getSortOptionsForCollection,
|
|
7912
9952
|
parseDynamicZonePath
|
|
7913
9953
|
};
|
|
7914
|
-
//# sourceMappingURL=BulkUpdater-
|
|
9954
|
+
//# sourceMappingURL=BulkUpdater-CTKfvKhE.mjs.map
|