strapi-plugin-bulk-updater 1.5.12 → 1.5.14

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.
@@ -114,6 +114,16 @@ function isValidDocId(val) {
114
114
  }
115
115
  function extractDocId(row) {
116
116
  if (!row || typeof row !== "object") return "";
117
+ const metaRaw = row.__bulk_updater_metadata || row["__bulk_updater_metadata"];
118
+ if (metaRaw) {
119
+ try {
120
+ const meta = typeof metaRaw === "object" ? metaRaw : JSON.parse(metaRaw);
121
+ if (meta?.documentId && isValidDocId(String(meta.documentId).trim())) {
122
+ return String(meta.documentId).trim();
123
+ }
124
+ } catch {
125
+ }
126
+ }
117
127
  const candidates = [
118
128
  row.documentId,
119
129
  row.document_id,
@@ -3862,7 +3872,19 @@ const BulkUpdater = () => {
3862
3872
  const [rollingBackBatchId, setRollingBackBatchId] = useState(null);
3863
3873
  const [expandedDiffBatchId, setExpandedDiffBatchId] = useState(null);
3864
3874
  const [auditNotice, setAuditNotice] = useState(null);
3865
- const latestActiveBatch = auditHistory.find((rec) => !rec.isRolledBack);
3875
+ const sortedAuditHistory = useMemo(() => {
3876
+ return [...auditHistory].sort((a, b) => {
3877
+ const timeA = a.executedAt || a.createdAt ? new Date(a.executedAt || a.createdAt).getTime() : 0;
3878
+ const validTimeA = Number.isNaN(timeA) ? 0 : timeA;
3879
+ const timeB = b.executedAt || b.createdAt ? new Date(b.executedAt || b.createdAt).getTime() : 0;
3880
+ const validTimeB = Number.isNaN(timeB) ? 0 : timeB;
3881
+ if (validTimeB !== validTimeA) return validTimeB - validTimeA;
3882
+ if (typeof a.id === "number" && typeof b.id === "number") return b.id - a.id;
3883
+ return String(b.id || b.batchId || "").localeCompare(String(a.id || a.batchId || ""));
3884
+ });
3885
+ }, [auditHistory]);
3886
+ const latestCompletedBatch = sortedAuditHistory.length > 0 ? sortedAuditHistory[0] : null;
3887
+ const latestActiveBatch = latestCompletedBatch && !latestCompletedBatch.isRolledBack ? latestCompletedBatch : null;
3866
3888
  const applyModelsData = (data) => {
3867
3889
  if (!data) return;
3868
3890
  const attrs = data.attributes || [];
@@ -6763,7 +6785,7 @@ const BulkUpdater = () => {
6763
6785
  /* @__PURE__ */ jsx(Typography, { variant: "beta", textColor: "neutral600", children: "No batch operations recorded in the audit trail yet." }),
6764
6786
  /* @__PURE__ */ jsx(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." })
6765
6787
  ] }),
6766
- auditHistory.length > 0 && /* @__PURE__ */ jsx(Box, { className: "bulk-updater-table-container", style: { width: "100%", maxWidth: "100%", minWidth: 0, overflowX: "auto" }, children: /* @__PURE__ */ jsxs(Table, { colCount: 6, rowCount: auditHistory.length + 1, style: { width: "100%" }, children: [
6788
+ sortedAuditHistory.length > 0 && /* @__PURE__ */ jsx(Box, { className: "bulk-updater-table-container", style: { width: "100%", maxWidth: "100%", minWidth: 0, overflowX: "auto" }, children: /* @__PURE__ */ jsxs(Table, { colCount: 6, rowCount: sortedAuditHistory.length + 1, style: { width: "100%" }, children: [
6767
6789
  /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
6768
6790
  /* @__PURE__ */ jsx(Th, { style: { minWidth: 140 }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Date & Time" }) }),
6769
6791
  /* @__PURE__ */ jsx(Th, { style: { minWidth: 130 }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Performed By" }) }),
@@ -6772,9 +6794,12 @@ const BulkUpdater = () => {
6772
6794
  /* @__PURE__ */ jsx(Th, { style: { minWidth: 120 }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Status" }) }),
6773
6795
  /* @__PURE__ */ jsx(Th, { style: { minWidth: 160, textAlign: "right" }, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Actions" }) })
6774
6796
  ] }) }),
6775
- /* @__PURE__ */ jsx(Tbody, { children: auditHistory.map((rec) => {
6797
+ /* @__PURE__ */ jsx(Tbody, { children: sortedAuditHistory.map((rec) => {
6776
6798
  const isExpanded = expandedDiffBatchId === rec.batchId;
6777
6799
  const dateStr = new Date(rec.executedAt).toLocaleString();
6800
+ const isLatestEligible = Boolean(
6801
+ rec.isLatestEligible ?? (latestCompletedBatch && rec.batchId === latestCompletedBatch.batchId && !latestCompletedBatch.isRolledBack)
6802
+ );
6778
6803
  return /* @__PURE__ */ jsxs(React__default.Fragment, { children: [
6779
6804
  /* @__PURE__ */ jsxs(
6780
6805
  Tr,
@@ -6876,7 +6901,7 @@ const BulkUpdater = () => {
6876
6901
  children: isExpanded ? "Hide Diffs" : "View Diffs"
6877
6902
  }
6878
6903
  ),
6879
- !rec.isRolledBack && /* @__PURE__ */ jsx(
6904
+ !rec.isRolledBack && (isLatestEligible ? /* @__PURE__ */ jsx(
6880
6905
  Button,
6881
6906
  {
6882
6907
  variant: "danger",
@@ -6885,7 +6910,23 @@ const BulkUpdater = () => {
6885
6910
  onClick: () => handleRollback(rec.batchId),
6886
6911
  children: "Rollback"
6887
6912
  }
6888
- )
6913
+ ) : /* @__PURE__ */ jsx(
6914
+ "span",
6915
+ {
6916
+ title: "Only the latest completed update can be rolled back.",
6917
+ style: { display: "inline-flex", cursor: "not-allowed" },
6918
+ children: /* @__PURE__ */ jsx(
6919
+ Button,
6920
+ {
6921
+ variant: "danger",
6922
+ size: "S",
6923
+ disabled: true,
6924
+ style: { opacity: 0.4, pointerEvents: "none" },
6925
+ children: "Rollback"
6926
+ }
6927
+ )
6928
+ }
6929
+ ))
6889
6930
  ] }) })
6890
6931
  ]
6891
6932
  }
@@ -7668,4 +7709,4 @@ export {
7668
7709
  getSortOptionsForCollection,
7669
7710
  parseDynamicZonePath
7670
7711
  };
7671
- //# sourceMappingURL=BulkUpdater-GPpE8YW2.mjs.map
7712
+ //# sourceMappingURL=BulkUpdater-B3m2_z--.mjs.map