strapi-plugin-bulk-updater 1.5.13 → 1.5.15

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.
@@ -118,6 +118,16 @@ function isValidDocId(val) {
118
118
  }
119
119
  function extractDocId(row) {
120
120
  if (!row || typeof row !== "object") return "";
121
+ const metaRaw = row.__bulk_updater_metadata || row["__bulk_updater_metadata"];
122
+ if (metaRaw) {
123
+ try {
124
+ const meta = typeof metaRaw === "object" ? metaRaw : JSON.parse(metaRaw);
125
+ if (meta?.documentId && isValidDocId(String(meta.documentId).trim())) {
126
+ return String(meta.documentId).trim();
127
+ }
128
+ } catch {
129
+ }
130
+ }
121
131
  const candidates = [
122
132
  row.documentId,
123
133
  row.document_id,
@@ -228,11 +238,23 @@ function getEntryLifecycleStatus(entry, col, pendingBatches = []) {
228
238
  function CsvManagerTab() {
229
239
  const { get, post } = admin.useFetchClient();
230
240
  const { toggleNotification } = admin.useNotification();
241
+ const fileInputRef = React.useRef(null);
242
+ const countAbortControllerRef = React.useRef(null);
231
243
  const [collections, setCollections] = React.useState([]);
232
244
  const [loadingCollections, setLoadingCollections] = React.useState(true);
233
245
  const [selectedUid, setSelectedUid] = React.useState("");
234
246
  const [collectionEntries, setCollectionEntries] = React.useState([]);
235
247
  const [pendingBatches, setPendingBatches] = React.useState([]);
248
+ const [relationsMeta, setRelationsMeta] = React.useState({});
249
+ const [attributesMeta, setAttributesMeta] = React.useState({});
250
+ const [searchAttribute, setSearchAttribute] = React.useState("");
251
+ const [filterOperator, setFilterOperator] = React.useState("none");
252
+ const [filterQuery, setFilterQuery] = React.useState("");
253
+ const [entrySearch, setEntrySearch] = React.useState("");
254
+ const [matchingCount, setMatchingCount] = React.useState(null);
255
+ const [countLoading, setCountLoading] = React.useState(false);
256
+ const [searchRelationOptions, setSearchRelationOptions] = React.useState([]);
257
+ const [searchRelationOptionsLoading, setSearchRelationOptionsLoading] = React.useState(false);
236
258
  const [exportLimit, setExportLimit] = React.useState(0);
237
259
  const [exportLimitInput, setExportLimitInput] = React.useState("");
238
260
  const [exportingCollection, setExportingCollection] = React.useState(false);
@@ -280,10 +302,12 @@ function CsvManagerTab() {
280
302
  if (modelsRes.data?.collections) {
281
303
  loadedCollections = modelsRes.data.collections;
282
304
  setCollections(loadedCollections);
283
- if (loadedCollections.length > 0) {
284
- const firstUid = loadedCollections[0].uid;
285
- setSelectedUid(firstUid);
286
- }
305
+ }
306
+ if (modelsRes.data?.relationsMeta) {
307
+ setRelationsMeta(modelsRes.data.relationsMeta);
308
+ }
309
+ if (modelsRes.data?.attributesMeta) {
310
+ setAttributesMeta(modelsRes.data.attributesMeta);
287
311
  }
288
312
  if (rulesRes.data?.rules) {
289
313
  setRules(rulesRes.data.rules);
@@ -301,6 +325,96 @@ function CsvManagerTab() {
301
325
  setLoadingCollections(false);
302
326
  }
303
327
  };
328
+ const getAttrDepth = (attr) => attributesMeta[attr]?.depth ?? (attr.includes(".") ? attr.split(".").length - 1 : 0);
329
+ React.useEffect(() => {
330
+ if (searchAttribute && relationsMeta[searchAttribute]) {
331
+ fetchSearchRelationOptions(relationsMeta[searchAttribute].targetUid);
332
+ } else {
333
+ setSearchRelationOptions([]);
334
+ }
335
+ }, [searchAttribute, relationsMeta]);
336
+ const fetchSearchRelationOptions = async (targetUid) => {
337
+ try {
338
+ setSearchRelationOptionsLoading(true);
339
+ const res = await get(`/bulk-updater/relation-options?targetUid=${encodeURIComponent(targetUid)}`);
340
+ if (res.data && res.data.success) {
341
+ setSearchRelationOptions(res.data.options || []);
342
+ }
343
+ } catch {
344
+ setSearchRelationOptions([]);
345
+ } finally {
346
+ setSearchRelationOptionsLoading(false);
347
+ }
348
+ };
349
+ const handleCollectionChange = (newUid) => {
350
+ if (newUid === selectedUid) return;
351
+ if (countAbortControllerRef.current) {
352
+ countAbortControllerRef.current.abort();
353
+ }
354
+ setSelectedUid(newUid);
355
+ setAllParsedRecords([]);
356
+ setCsvRawText("");
357
+ setFileName("");
358
+ setPreviewPage(1);
359
+ setImportProgress(null);
360
+ setImportResult(null);
361
+ setPreflightReport(null);
362
+ setPreflightLoading(false);
363
+ setImporting(false);
364
+ if (fileInputRef.current) {
365
+ fileInputRef.current.value = "";
366
+ }
367
+ setSearchAttribute("");
368
+ setFilterOperator("none");
369
+ setFilterQuery("");
370
+ setEntrySearch("");
371
+ setMatchingCount(null);
372
+ setCountLoading(Boolean(newUid));
373
+ };
374
+ React.useEffect(() => {
375
+ if (!selectedUid) {
376
+ setMatchingCount(null);
377
+ setCountLoading(false);
378
+ return;
379
+ }
380
+ setCountLoading(true);
381
+ const timer = setTimeout(async () => {
382
+ if (countAbortControllerRef.current) {
383
+ countAbortControllerRef.current.abort();
384
+ }
385
+ const controller = new AbortController();
386
+ countAbortControllerRef.current = controller;
387
+ try {
388
+ const params = new URLSearchParams({
389
+ page: "1",
390
+ pageSize: "1"
391
+ });
392
+ if (searchAttribute) {
393
+ params.set("attribute", searchAttribute);
394
+ params.set("searchAttribute", searchAttribute);
395
+ }
396
+ if (filterOperator && filterOperator !== "none") {
397
+ params.set("filterOperator", filterOperator);
398
+ if (filterQuery) params.set("filterQuery", filterQuery);
399
+ }
400
+ if (entrySearch && entrySearch.trim()) {
401
+ params.set("search", entrySearch.trim());
402
+ }
403
+ const res = await get(`/bulk-updater/collections/${selectedUid}/entries?${params.toString()}`, {
404
+ signal: controller.signal
405
+ });
406
+ if (res.data) {
407
+ const total = res.data.pagination?.total ?? (Array.isArray(res.data.entries) ? res.data.entries.length : 0);
408
+ setMatchingCount(total);
409
+ }
410
+ } catch (err) {
411
+ if (!ValidationRulesTab.isAbortError(err)) ;
412
+ } finally {
413
+ setCountLoading(false);
414
+ }
415
+ }, 300);
416
+ return () => clearTimeout(timer);
417
+ }, [selectedUid, searchAttribute, filterOperator, filterQuery, entrySearch]);
304
418
  const fetchAndEnrichEntries = async (colUid, cols = collections, batches = pendingBatches) => {
305
419
  if (!colUid) return [];
306
420
  try {
@@ -383,7 +497,17 @@ function CsvManagerTab() {
383
497
  if (!selectedUid || exportingCollection) return;
384
498
  try {
385
499
  setExportingCollection(true);
386
- const res = await get(`/bulk-updater/csv/export/${selectedUid}?limit=${exportLimit}`);
500
+ const queryParams = new URLSearchParams();
501
+ if (exportLimit > 0) queryParams.set("limit", String(exportLimit));
502
+ if (searchAttribute) queryParams.set("searchAttribute", searchAttribute);
503
+ if (filterOperator && filterOperator !== "none") {
504
+ queryParams.set("filterOperator", filterOperator);
505
+ if (filterQuery) queryParams.set("filterQuery", filterQuery);
506
+ }
507
+ if (entrySearch && entrySearch.trim()) {
508
+ queryParams.set("search", entrySearch.trim());
509
+ }
510
+ const res = await get(`/bulk-updater/csv/export/${selectedUid}?${queryParams.toString()}`);
387
511
  const csvStr = res.data?.csvContent || (typeof res.data === "string" ? res.data : "");
388
512
  const filename = res.data?.filename || `${selectedUid.split(".").pop()}_export.csv`;
389
513
  downloadCsvFile(csvStr, filename);
@@ -667,23 +791,15 @@ function CsvManagerTab() {
667
791
  {
668
792
  value: selectedUid || void 0,
669
793
  autocomplete: { type: "list", filter: "contains" },
670
- placeholder: "Search & select a collection...",
794
+ placeholder: "Select Collection Type...",
671
795
  disabled: loadingCollections,
672
796
  clearLabel: "Clear collection selection",
673
- onClear: () => {
674
- setSelectedUid("");
675
- setImportResult(null);
676
- setImportProgress(null);
677
- },
797
+ onClear: () => handleCollectionChange(""),
678
798
  onFocus: (e) => {
679
799
  e.target.select();
680
800
  },
681
801
  onChange: (val) => {
682
- if (val && typeof val === "string") {
683
- setSelectedUid(val);
684
- setImportResult(null);
685
- setImportProgress(null);
686
- }
802
+ handleCollectionChange(val ? String(val) : "");
687
803
  },
688
804
  children: collections.map((col) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.ComboboxOption, { value: col.uid, textValue: `${col.displayName} (${col.uid})`, children: [
689
805
  col.displayName,
@@ -709,7 +825,139 @@ function CsvManagerTab() {
709
825
  ] }) }),
710
826
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 5, background: "neutral100", hasRadius: true, children: [
711
827
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h3", fontWeight: "bold", marginBottom: 2, children: "1. Export Data to CSV" }),
712
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", marginBottom: 4, children: "Extract entire collections without artificial limits (streams 10,000+ records in paged chunks) or pinpoint records violating validation quotas." }),
828
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", marginBottom: 4, children: "Extract entire collections or filtered subsets without artificial limits (streams 10,000+ records in paged chunks) or pinpoint records violating validation quotas." }),
829
+ selectedUid ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 4, background: "neutral0", hasRadius: true, marginBottom: 4, style: { border: "1px solid #eaeaef" }, children: [
830
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 3, children: [
831
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral700", textTransform: "uppercase", children: "Search & Filter Collection Before Export" }),
832
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", children: [
833
+ countLoading ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { backgroundColor: "neutral150", textColor: "neutral700", size: "S", children: "Calculating matching records..." }) : matchingCount !== null ? /* @__PURE__ */ jsxRuntime.jsxs(
834
+ designSystem.Badge,
835
+ {
836
+ backgroundColor: matchingCount > 0 ? "success100" : "warning100",
837
+ textColor: matchingCount > 0 ? "success700" : "warning700",
838
+ size: "S",
839
+ children: [
840
+ matchingCount.toLocaleString(),
841
+ " matching records found"
842
+ ]
843
+ }
844
+ ) : null,
845
+ (searchAttribute || filterOperator !== "none" || entrySearch.trim()) && /* @__PURE__ */ jsxRuntime.jsx(
846
+ designSystem.Button,
847
+ {
848
+ variant: "ghost",
849
+ size: "S",
850
+ onClick: () => {
851
+ setSearchAttribute("");
852
+ setFilterOperator("none");
853
+ setFilterQuery("");
854
+ setEntrySearch("");
855
+ },
856
+ children: "Clear Filters"
857
+ }
858
+ )
859
+ ] })
860
+ ] }),
861
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, alignItems: "flex-end", wrap: "wrap", children: [
862
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { width: 280, minWidth: 230 }, children: [
863
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", marginBottom: 1, display: "block", children: "Search Attribute" }),
864
+ /* @__PURE__ */ jsxRuntime.jsx(
865
+ designSystem.Combobox,
866
+ {
867
+ autocomplete: { type: "list", filter: "contains" },
868
+ placeholder: "Select Search Attribute...",
869
+ value: searchAttribute || void 0,
870
+ clearLabel: "Reset search attribute",
871
+ onClear: () => setSearchAttribute(""),
872
+ onFocus: (e) => {
873
+ e.target.select();
874
+ },
875
+ onChange: (val) => {
876
+ if (val && typeof val === "string" && val !== "__none__") {
877
+ setSearchAttribute(val);
878
+ }
879
+ },
880
+ children: (selectedCol?.attributes || []).map((attr) => {
881
+ const rel = relationsMeta[attr];
882
+ const depth = getAttrDepth(attr);
883
+ const badgeText = rel ? `relation ${rel.targetDisplayName}` : depth > 0 ? `L${depth} component` : "";
884
+ const textValue = badgeText ? `${attr} ${badgeText}` : attr;
885
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.ComboboxOption, { value: attr, textValue, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", width: "100%", gap: 2, children: [
886
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: attr === searchAttribute ? "bold" : "regular", children: attr }),
887
+ rel ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: "secondary100", textColor: "secondary700", size: "S", children: [
888
+ "relation ➔ ",
889
+ rel.targetDisplayName
890
+ ] }) : depth > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: depth === 1 ? "neutral150" : depth === 2 ? "primary100" : "secondary100", textColor: depth === 1 ? "neutral700" : depth === 2 ? "primary700" : "secondary700", size: "S", children: [
891
+ "L",
892
+ depth,
893
+ " component"
894
+ ] }) : null
895
+ ] }) }, `search_${attr}`);
896
+ })
897
+ },
898
+ `csv-search-attr-${selectedUid}`
899
+ )
900
+ ] }),
901
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { width: 200, minWidth: 170 }, children: [
902
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", marginBottom: 1, display: "block", children: searchAttribute ? `Condition for "${searchAttribute}"` : "Filter condition" }),
903
+ /* @__PURE__ */ jsxRuntime.jsxs(
904
+ designSystem.SingleSelect,
905
+ {
906
+ value: filterOperator,
907
+ disabled: !searchAttribute,
908
+ onChange: (val) => setFilterOperator(String(val)),
909
+ children: [
910
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "none", children: "Show All (No Value Filter)" }),
911
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "empty", children: "Is Empty or Null" }),
912
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "not_empty", children: "Is Not Empty" }),
913
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "equals", children: "Equals Exact Text" }),
914
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "contains", children: "Contains Substring" }),
915
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "starts_with", children: "Starts With" })
916
+ ]
917
+ }
918
+ )
919
+ ] }),
920
+ (filterOperator === "equals" || filterOperator === "contains" || filterOperator === "starts_with") && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: 1, minWidth: 200 }, children: [
921
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", marginBottom: 1, display: "block", children: searchAttribute ? `Value for "${searchAttribute}"` : "Value to match" }),
922
+ searchAttribute && relationsMeta[searchAttribute] ? /* @__PURE__ */ jsxRuntime.jsx(
923
+ designSystem.Combobox,
924
+ {
925
+ autocomplete: { type: "list", filter: "contains" },
926
+ placeholder: searchRelationOptionsLoading ? "Loading entities..." : `Search & pick ${relationsMeta[searchAttribute].targetDisplayName} or type text...`,
927
+ value: filterQuery,
928
+ onClear: () => setFilterQuery(""),
929
+ onChange: (val) => {
930
+ if (typeof val === "string") {
931
+ setFilterQuery(val);
932
+ }
933
+ },
934
+ onInputChange: (e) => {
935
+ setFilterQuery(e.target.value);
936
+ },
937
+ children: searchRelationOptions.map((opt) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.ComboboxOption, { value: opt.label, textValue: opt.label, children: opt.label }, opt.documentId))
938
+ }
939
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
940
+ designSystem.TextInput,
941
+ {
942
+ placeholder: "Type value to match...",
943
+ value: filterQuery,
944
+ onChange: (e) => setFilterQuery(e.target.value)
945
+ }
946
+ )
947
+ ] }),
948
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: 1, minWidth: 200 }, children: [
949
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", marginBottom: 1, display: "block", children: "Full-text Entry Search" }),
950
+ /* @__PURE__ */ jsxRuntime.jsx(
951
+ designSystem.TextInput,
952
+ {
953
+ placeholder: "Search title, name, or text across records...",
954
+ value: entrySearch,
955
+ onChange: (e) => setEntrySearch(e.target.value)
956
+ }
957
+ )
958
+ ] })
959
+ ] })
960
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 4, background: "neutral0", hasRadius: true, marginBottom: 4, style: { border: "1px solid #eaeaef", textAlign: "center" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", children: "Please select a Target Collection Type above to configure search filters and export data." }) }),
713
961
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 4, wrap: "wrap", alignItems: "flex-end", marginTop: 3, children: [
714
962
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { width: 220 }, children: [
715
963
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", marginBottom: 1, display: "block", children: "Records to Download" }),
@@ -762,9 +1010,9 @@ function CsvManagerTab() {
762
1010
  variant: "default",
763
1011
  startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Download, {}),
764
1012
  onClick: handleExportCollection,
765
- disabled: !selectedUid || exportingCollection,
1013
+ disabled: !selectedUid || exportingCollection || matchingCount === 0,
766
1014
  loading: exportingCollection,
767
- children: exportingCollection ? "Preparing CSV download..." : `Export ${exportLimit === 0 ? "All" : exportLimit.toLocaleString()} ${selectedCol?.displayName || "Collection"} Records (.csv)`
1015
+ children: exportingCollection ? "Preparing CSV download..." : countLoading ? "Export (...) Records (.csv)" : matchingCount !== null ? exportLimit > 0 && matchingCount > exportLimit ? `Export First ${exportLimit.toLocaleString()} of (${matchingCount.toLocaleString()}) Records (.csv)` : `Export (${matchingCount.toLocaleString()}) ${selectedCol?.displayName || "Collection"} Records (.csv)` : `Export ${exportLimit === 0 ? "All" : exportLimit.toLocaleString()} ${selectedCol?.displayName || "Collection"} Records (.csv)`
768
1016
  }
769
1017
  ),
770
1018
  rules.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", style: { marginLeft: "auto" }, children: [
@@ -845,6 +1093,7 @@ function CsvManagerTab() {
845
1093
  type: "file",
846
1094
  accept: ".csv",
847
1095
  id: "csv-file-input",
1096
+ ref: fileInputRef,
848
1097
  style: { display: "none" },
849
1098
  onChange: handleFileUpload
850
1099
  }
@@ -3725,24 +3974,8 @@ const BulkUpdater = () => {
3725
3974
  const MODELS_CACHE_KEY = "strapi_bulk_updater_models_cache";
3726
3975
  const LAST_ATTR_KEY = "strapi_bulk_updater_last_attr";
3727
3976
  const LAST_COLLECTION_KEY = "strapi_bulk_updater_last_collection";
3728
- const getInitialCollectionUid = () => {
3729
- try {
3730
- const stored = localStorage.getItem(LAST_COLLECTION_KEY);
3731
- if (stored) return stored;
3732
- } catch {
3733
- }
3734
- return "";
3735
- };
3736
- const [selectedCollectionUid, setSelectedCollectionUid] = React.useState(getInitialCollectionUid);
3737
- const getInitialAttribute = () => {
3738
- try {
3739
- const stored = localStorage.getItem(LAST_ATTR_KEY);
3740
- if (stored) return stored;
3741
- } catch {
3742
- }
3743
- return "";
3744
- };
3745
- const [selectedAttribute, setSelectedAttribute] = React.useState(getInitialAttribute);
3977
+ const [selectedCollectionUid, setSelectedCollectionUid] = React.useState("");
3978
+ const [selectedAttribute, setSelectedAttribute] = React.useState("");
3746
3979
  const [attributeValue, setAttributeValue] = React.useState("");
3747
3980
  const [selectedEntries, setSelectedEntries] = React.useState({});
3748
3981
  const [expandedDzEntries, setExpandedDzEntries] = React.useState({});
@@ -3816,6 +4049,7 @@ const BulkUpdater = () => {
3816
4049
  const [filterOperator, setFilterOperator] = React.useState("none");
3817
4050
  const [filterQuery, setFilterQuery] = React.useState("");
3818
4051
  const [entrySearch, setEntrySearch] = React.useState("");
4052
+ const abortControllersRef = React.useRef({});
3819
4053
  const [statusFilter, setStatusFilter] = React.useState("all");
3820
4054
  const isFilterActive = Boolean(searchAttribute && searchAttribute !== selectedAttribute) || filterOperator !== "none" && (["empty", "not_empty"].includes(filterOperator) || Boolean(filterQuery.trim())) || Boolean(entrySearch.trim()) || Boolean(statusFilter !== "all") || Boolean(useRegex && regexPattern.trim());
3821
4055
  const [lastResults, setLastResults] = React.useState(null);
@@ -3866,7 +4100,19 @@ const BulkUpdater = () => {
3866
4100
  const [rollingBackBatchId, setRollingBackBatchId] = React.useState(null);
3867
4101
  const [expandedDiffBatchId, setExpandedDiffBatchId] = React.useState(null);
3868
4102
  const [auditNotice, setAuditNotice] = React.useState(null);
3869
- const latestActiveBatch = auditHistory.find((rec) => !rec.isRolledBack);
4103
+ const sortedAuditHistory = React.useMemo(() => {
4104
+ return [...auditHistory].sort((a, b) => {
4105
+ const timeA = a.executedAt || a.createdAt ? new Date(a.executedAt || a.createdAt).getTime() : 0;
4106
+ const validTimeA = Number.isNaN(timeA) ? 0 : timeA;
4107
+ const timeB = b.executedAt || b.createdAt ? new Date(b.executedAt || b.createdAt).getTime() : 0;
4108
+ const validTimeB = Number.isNaN(timeB) ? 0 : timeB;
4109
+ if (validTimeB !== validTimeA) return validTimeB - validTimeA;
4110
+ if (typeof a.id === "number" && typeof b.id === "number") return b.id - a.id;
4111
+ return String(b.id || b.batchId || "").localeCompare(String(a.id || a.batchId || ""));
4112
+ });
4113
+ }, [auditHistory]);
4114
+ const latestCompletedBatch = sortedAuditHistory.length > 0 ? sortedAuditHistory[0] : null;
4115
+ const latestActiveBatch = latestCompletedBatch && !latestCompletedBatch.isRolledBack ? latestCompletedBatch : null;
3870
4116
  const applyModelsData = (data) => {
3871
4117
  if (!data) return;
3872
4118
  const attrs = data.attributes || [];
@@ -3915,28 +4161,14 @@ const BulkUpdater = () => {
3915
4161
  setAttributesMeta(data.attributesMeta);
3916
4162
  }
3917
4163
  let resolvedColUid = selectedCollectionUid;
3918
- let storedCol = null;
3919
- try {
3920
- storedCol = localStorage.getItem(LAST_COLLECTION_KEY);
3921
- } catch {
3922
- }
3923
- if (!resolvedColUid || !cols.some((c) => c.uid === resolvedColUid)) {
3924
- resolvedColUid = storedCol && cols.some((c) => c.uid === storedCol) ? storedCol : cols[0]?.uid || "";
4164
+ if (resolvedColUid && !cols.some((c) => c.uid === resolvedColUid)) {
4165
+ resolvedColUid = "";
3925
4166
  }
3926
4167
  setSelectedCollectionUid(resolvedColUid);
3927
- try {
3928
- if (resolvedColUid) localStorage.setItem(LAST_COLLECTION_KEY, resolvedColUid);
3929
- } catch {
3930
- }
3931
- const activeCol = cols.find((c) => c.uid === resolvedColUid) || cols[0];
4168
+ const activeCol = resolvedColUid ? cols.find((c) => c.uid === resolvedColUid) : null;
3932
4169
  const activeAttrs = activeCol?.attributes || [];
3933
4170
  setAttributes(activeAttrs);
3934
- let storedAttr = null;
3935
- try {
3936
- storedAttr = localStorage.getItem(LAST_ATTR_KEY);
3937
- } catch {
3938
- }
3939
- const resolvedAttr = storedAttr && activeAttrs.includes(storedAttr) ? storedAttr : selectedAttribute && activeAttrs.includes(selectedAttribute) ? selectedAttribute : "";
4171
+ const resolvedAttr = selectedAttribute && activeAttrs.includes(selectedAttribute) ? selectedAttribute : "";
3940
4172
  setSelectedAttribute(resolvedAttr);
3941
4173
  if (resolvedAttr && data.relationsMeta && data.relationsMeta[resolvedAttr]) {
3942
4174
  fetchRelationOptions(data.relationsMeta[resolvedAttr].targetUid);
@@ -4017,7 +4249,14 @@ const BulkUpdater = () => {
4017
4249
  params.set("sortField", sortField);
4018
4250
  params.set("sortOrder", sortOrder);
4019
4251
  }
4020
- const res = await get(`/bulk-updater/collections/${colUid}/entries?${params.toString()}`);
4252
+ if (abortControllersRef.current[colUid]) {
4253
+ abortControllersRef.current[colUid].abort();
4254
+ }
4255
+ const controller = new AbortController();
4256
+ abortControllersRef.current[colUid] = controller;
4257
+ const res = await get(`/bulk-updater/collections/${colUid}/entries?${params.toString()}`, {
4258
+ signal: controller.signal
4259
+ });
4021
4260
  if (res.data && (res.data.success || res.data.entries !== void 0)) {
4022
4261
  const fetchedEntries = res.data.entries || [];
4023
4262
  const pageNum = res.data.pagination?.page ?? targetPage ?? 1;
@@ -4159,6 +4398,9 @@ const BulkUpdater = () => {
4159
4398
  }, [collections, selectedCollectionUid]);
4160
4399
  const handleCollectionChange = (newUid) => {
4161
4400
  if (newUid === selectedCollectionUid) return;
4401
+ if (abortControllersRef.current) {
4402
+ Object.values(abortControllersRef.current).forEach((ctrl) => ctrl.abort());
4403
+ }
4162
4404
  setSelectedCollectionUid(newUid);
4163
4405
  try {
4164
4406
  if (newUid) {
@@ -4248,59 +4490,40 @@ const BulkUpdater = () => {
4248
4490
  });
4249
4491
  }, [depthFilteredAttributes, relationsMeta, selectedAttribute, componentDepth, attributesMeta]);
4250
4492
  const memoizedSearchComboboxOptions = React.useMemo(() => {
4251
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4252
- /* @__PURE__ */ jsxRuntime.jsx(
4253
- designSystem.ComboboxOption,
4254
- {
4255
- value: "__default__",
4256
- textValue: `Same as Update Attribute (${selectedAttribute || "None"}) default`,
4257
- children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", width: "100%", gap: 2, children: [
4258
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "omega", fontStyle: "italic", textColor: "neutral600", children: [
4259
- "-- Same as Update Attribute (",
4260
- selectedAttribute || "None",
4261
- ") --"
4262
- ] }),
4263
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { backgroundColor: "neutral150", textColor: "neutral600", size: "S", children: "Default" })
4264
- ] })
4265
- }
4266
- ),
4267
- depthFilteredAttributes.map((attr) => {
4268
- const rel = relationsMeta[attr];
4269
- const depth = getAttrDepth(attr);
4270
- const badgeText = rel ? `relation ${rel.targetDisplayName}` : depth > 0 ? `L${depth} component` : "";
4271
- const textValue = badgeText ? `${attr} ${badgeText}` : attr;
4272
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.ComboboxOption, { value: attr, textValue, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", width: "100%", gap: 2, children: [
4273
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: attr === searchAttribute ? "bold" : "regular", children: attr }),
4274
- rel ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: "secondary100", textColor: "secondary700", size: "S", children: [
4275
- "relation ➔ ",
4276
- rel.targetDisplayName
4277
- ] }) : depth > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: depth === 1 ? "neutral150" : depth === 2 ? "primary100" : "secondary100", textColor: depth === 1 ? "neutral700" : depth === 2 ? "primary700" : "secondary700", size: "S", children: [
4278
- "L",
4279
- depth,
4280
- " component"
4281
- ] }) : null
4282
- ] }) }, `search_${attr}`);
4283
- })
4284
- ] });
4493
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: depthFilteredAttributes.map((attr) => {
4494
+ const rel = relationsMeta[attr];
4495
+ const depth = getAttrDepth(attr);
4496
+ const badgeText = rel ? `relation ${rel.targetDisplayName}` : depth > 0 ? `L${depth} component` : "";
4497
+ const textValue = badgeText ? `${attr} ${badgeText}` : attr;
4498
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.ComboboxOption, { value: attr, textValue, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", width: "100%", gap: 2, children: [
4499
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: attr === searchAttribute ? "bold" : "regular", children: attr }),
4500
+ rel ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: "secondary100", textColor: "secondary700", size: "S", children: [
4501
+ "relation ➔ ",
4502
+ rel.targetDisplayName
4503
+ ] }) : depth > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: depth === 1 ? "neutral150" : depth === 2 ? "primary100" : "secondary100", textColor: depth === 1 ? "neutral700" : depth === 2 ? "primary700" : "secondary700", size: "S", children: [
4504
+ "L",
4505
+ depth,
4506
+ " component"
4507
+ ] }) : null
4508
+ ] }) }, `search_${attr}`);
4509
+ }) });
4285
4510
  }, [depthFilteredAttributes, relationsMeta, searchAttribute, selectedAttribute, componentDepth, attributesMeta]);
4286
4511
  const handleSearchAttributeChange = (newAttr) => {
4287
4512
  const finalAttr = newAttr === "__default__" ? "" : newAttr;
4288
4513
  setSearchAttribute(finalAttr);
4289
- if (collections.length > 0) {
4290
- collections.forEach((col) => {
4291
- loadCollectionPage(
4292
- col.uid,
4293
- 1,
4294
- void 0,
4295
- void 0,
4296
- void 0,
4297
- filterOperator,
4298
- filterQuery,
4299
- entrySearch,
4300
- true,
4301
- finalAttr
4302
- );
4303
- });
4514
+ if (selectedCollectionUid) {
4515
+ loadCollectionPage(
4516
+ selectedCollectionUid,
4517
+ 1,
4518
+ void 0,
4519
+ void 0,
4520
+ void 0,
4521
+ filterOperator,
4522
+ filterQuery,
4523
+ entrySearch,
4524
+ true,
4525
+ finalAttr
4526
+ );
4304
4527
  }
4305
4528
  };
4306
4529
  const handleCollectionPageSizeChange = (colUid, newSize) => {
@@ -5396,7 +5619,7 @@ const BulkUpdater = () => {
5396
5619
  designSystem.Combobox,
5397
5620
  {
5398
5621
  autocomplete: { type: "list", filter: "contains" },
5399
- placeholder: "Search Collection Type...",
5622
+ placeholder: "Select Collection Type...",
5400
5623
  value: selectedCollectionUid || void 0,
5401
5624
  clearLabel: "Clear collection selection",
5402
5625
  onClear: () => handleCollectionChange(""),
@@ -5497,8 +5720,8 @@ const BulkUpdater = () => {
5497
5720
  designSystem.Combobox,
5498
5721
  {
5499
5722
  autocomplete: { type: "list", filter: "contains" },
5500
- placeholder: searchAttribute || `Same as Update (${selectedAttribute || "None"})`,
5501
- value: searchAttribute || "__default__",
5723
+ placeholder: "Select Search Attribute...",
5724
+ value: searchAttribute || void 0,
5502
5725
  clearLabel: "Reset search attribute",
5503
5726
  onClear: () => handleSearchAttributeChange(""),
5504
5727
  onFocus: (e) => {
@@ -5517,8 +5740,9 @@ const BulkUpdater = () => {
5517
5740
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { width: 200, minWidth: 170 }, children: /* @__PURE__ */ jsxRuntime.jsxs(
5518
5741
  designSystem.SingleSelect,
5519
5742
  {
5520
- label: effectiveSearchAttribute ? `Condition for "${effectiveSearchAttribute}"` : "Filter condition",
5743
+ label: searchAttribute ? `Condition for "${searchAttribute}"` : "Filter condition",
5521
5744
  value: filterOperator,
5745
+ disabled: !searchAttribute,
5522
5746
  onChange: (val) => setFilterOperator(String(val)),
5523
5747
  children: [
5524
5748
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "none", children: "Show All (No Value Filter)" }),
@@ -6286,7 +6510,7 @@ const BulkUpdater = () => {
6286
6510
  designSystem.Combobox,
6287
6511
  {
6288
6512
  autocomplete: { type: "list", filter: "contains" },
6289
- placeholder: "Search attribute by name or relation...",
6513
+ placeholder: "Select Attribute to Update...",
6290
6514
  value: selectedAttribute || void 0,
6291
6515
  clearLabel: "Clear attribute selection",
6292
6516
  onClear: () => handleAttributeChange(""),
@@ -6767,7 +6991,7 @@ const BulkUpdater = () => {
6767
6991
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "beta", textColor: "neutral600", children: "No batch operations recorded in the audit trail yet." }),
6768
6992
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", display: "block", marginTop: 2, children: "When you execute a bulk update in the editor, its transactional diff will be logged here." })
6769
6993
  ] }),
6770
- auditHistory.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { className: "bulk-updater-table-container", style: { width: "100%", maxWidth: "100%", minWidth: 0, overflowX: "auto" }, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { colCount: 6, rowCount: auditHistory.length + 1, style: { width: "100%" }, children: [
6994
+ sortedAuditHistory.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { className: "bulk-updater-table-container", style: { width: "100%", maxWidth: "100%", minWidth: 0, overflowX: "auto" }, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { colCount: 6, rowCount: sortedAuditHistory.length + 1, style: { width: "100%" }, children: [
6771
6995
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
6772
6996
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { style: { minWidth: 140 }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Date & Time" }) }),
6773
6997
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { style: { minWidth: 130 }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Performed By" }) }),
@@ -6776,9 +7000,12 @@ const BulkUpdater = () => {
6776
7000
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { style: { minWidth: 120 }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Status" }) }),
6777
7001
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { style: { minWidth: 160, textAlign: "right" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Actions" }) })
6778
7002
  ] }) }),
6779
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: auditHistory.map((rec) => {
7003
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: sortedAuditHistory.map((rec) => {
6780
7004
  const isExpanded = expandedDiffBatchId === rec.batchId;
6781
7005
  const dateStr = new Date(rec.executedAt).toLocaleString();
7006
+ const isLatestEligible = Boolean(
7007
+ rec.isLatestEligible ?? (latestCompletedBatch && rec.batchId === latestCompletedBatch.batchId && !latestCompletedBatch.isRolledBack)
7008
+ );
6782
7009
  return /* @__PURE__ */ jsxRuntime.jsxs(React__default.default.Fragment, { children: [
6783
7010
  /* @__PURE__ */ jsxRuntime.jsxs(
6784
7011
  designSystem.Tr,
@@ -6880,7 +7107,7 @@ const BulkUpdater = () => {
6880
7107
  children: isExpanded ? "Hide Diffs" : "View Diffs"
6881
7108
  }
6882
7109
  ),
6883
- !rec.isRolledBack && /* @__PURE__ */ jsxRuntime.jsx(
7110
+ !rec.isRolledBack && (isLatestEligible ? /* @__PURE__ */ jsxRuntime.jsx(
6884
7111
  designSystem.Button,
6885
7112
  {
6886
7113
  variant: "danger",
@@ -6889,7 +7116,23 @@ const BulkUpdater = () => {
6889
7116
  onClick: () => handleRollback(rec.batchId),
6890
7117
  children: "Rollback"
6891
7118
  }
6892
- )
7119
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
7120
+ "span",
7121
+ {
7122
+ title: "Only the latest completed update can be rolled back.",
7123
+ style: { display: "inline-flex", cursor: "not-allowed" },
7124
+ children: /* @__PURE__ */ jsxRuntime.jsx(
7125
+ designSystem.Button,
7126
+ {
7127
+ variant: "danger",
7128
+ size: "S",
7129
+ disabled: true,
7130
+ style: { opacity: 0.4, pointerEvents: "none" },
7131
+ children: "Rollback"
7132
+ }
7133
+ )
7134
+ }
7135
+ ))
6893
7136
  ] }) })
6894
7137
  ]
6895
7138
  }
@@ -7670,4 +7913,4 @@ exports.getNestedValue = getNestedValue;
7670
7913
  exports.getPropertyValue = getPropertyValue;
7671
7914
  exports.getSortOptionsForCollection = getSortOptionsForCollection;
7672
7915
  exports.parseDynamicZonePath = parseDynamicZonePath;
7673
- //# sourceMappingURL=BulkUpdater-VwNHxQId.js.map
7916
+ //# sourceMappingURL=BulkUpdater-CrmdSFUB.js.map