strapi-plugin-bulk-updater 1.5.13 → 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.
@@ -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,
@@ -3866,7 +3876,19 @@ const BulkUpdater = () => {
3866
3876
  const [rollingBackBatchId, setRollingBackBatchId] = React.useState(null);
3867
3877
  const [expandedDiffBatchId, setExpandedDiffBatchId] = React.useState(null);
3868
3878
  const [auditNotice, setAuditNotice] = React.useState(null);
3869
- const latestActiveBatch = auditHistory.find((rec) => !rec.isRolledBack);
3879
+ const sortedAuditHistory = React.useMemo(() => {
3880
+ return [...auditHistory].sort((a, b) => {
3881
+ const timeA = a.executedAt || a.createdAt ? new Date(a.executedAt || a.createdAt).getTime() : 0;
3882
+ const validTimeA = Number.isNaN(timeA) ? 0 : timeA;
3883
+ const timeB = b.executedAt || b.createdAt ? new Date(b.executedAt || b.createdAt).getTime() : 0;
3884
+ const validTimeB = Number.isNaN(timeB) ? 0 : timeB;
3885
+ if (validTimeB !== validTimeA) return validTimeB - validTimeA;
3886
+ if (typeof a.id === "number" && typeof b.id === "number") return b.id - a.id;
3887
+ return String(b.id || b.batchId || "").localeCompare(String(a.id || a.batchId || ""));
3888
+ });
3889
+ }, [auditHistory]);
3890
+ const latestCompletedBatch = sortedAuditHistory.length > 0 ? sortedAuditHistory[0] : null;
3891
+ const latestActiveBatch = latestCompletedBatch && !latestCompletedBatch.isRolledBack ? latestCompletedBatch : null;
3870
3892
  const applyModelsData = (data) => {
3871
3893
  if (!data) return;
3872
3894
  const attrs = data.attributes || [];
@@ -6767,7 +6789,7 @@ const BulkUpdater = () => {
6767
6789
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "beta", textColor: "neutral600", children: "No batch operations recorded in the audit trail yet." }),
6768
6790
  /* @__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
6791
  ] }),
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: [
6792
+ 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
6793
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
6772
6794
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { style: { minWidth: 140 }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Date & Time" }) }),
6773
6795
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { style: { minWidth: 130 }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Performed By" }) }),
@@ -6776,9 +6798,12 @@ const BulkUpdater = () => {
6776
6798
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { style: { minWidth: 120 }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Status" }) }),
6777
6799
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { style: { minWidth: 160, textAlign: "right" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Actions" }) })
6778
6800
  ] }) }),
6779
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: auditHistory.map((rec) => {
6801
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: sortedAuditHistory.map((rec) => {
6780
6802
  const isExpanded = expandedDiffBatchId === rec.batchId;
6781
6803
  const dateStr = new Date(rec.executedAt).toLocaleString();
6804
+ const isLatestEligible = Boolean(
6805
+ rec.isLatestEligible ?? (latestCompletedBatch && rec.batchId === latestCompletedBatch.batchId && !latestCompletedBatch.isRolledBack)
6806
+ );
6782
6807
  return /* @__PURE__ */ jsxRuntime.jsxs(React__default.default.Fragment, { children: [
6783
6808
  /* @__PURE__ */ jsxRuntime.jsxs(
6784
6809
  designSystem.Tr,
@@ -6880,7 +6905,7 @@ const BulkUpdater = () => {
6880
6905
  children: isExpanded ? "Hide Diffs" : "View Diffs"
6881
6906
  }
6882
6907
  ),
6883
- !rec.isRolledBack && /* @__PURE__ */ jsxRuntime.jsx(
6908
+ !rec.isRolledBack && (isLatestEligible ? /* @__PURE__ */ jsxRuntime.jsx(
6884
6909
  designSystem.Button,
6885
6910
  {
6886
6911
  variant: "danger",
@@ -6889,7 +6914,23 @@ const BulkUpdater = () => {
6889
6914
  onClick: () => handleRollback(rec.batchId),
6890
6915
  children: "Rollback"
6891
6916
  }
6892
- )
6917
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
6918
+ "span",
6919
+ {
6920
+ title: "Only the latest completed update can be rolled back.",
6921
+ style: { display: "inline-flex", cursor: "not-allowed" },
6922
+ children: /* @__PURE__ */ jsxRuntime.jsx(
6923
+ designSystem.Button,
6924
+ {
6925
+ variant: "danger",
6926
+ size: "S",
6927
+ disabled: true,
6928
+ style: { opacity: 0.4, pointerEvents: "none" },
6929
+ children: "Rollback"
6930
+ }
6931
+ )
6932
+ }
6933
+ ))
6893
6934
  ] }) })
6894
6935
  ]
6895
6936
  }
@@ -7670,4 +7711,4 @@ exports.getNestedValue = getNestedValue;
7670
7711
  exports.getPropertyValue = getPropertyValue;
7671
7712
  exports.getSortOptionsForCollection = getSortOptionsForCollection;
7672
7713
  exports.parseDynamicZonePath = parseDynamicZonePath;
7673
- //# sourceMappingURL=BulkUpdater-VwNHxQId.js.map
7714
+ //# sourceMappingURL=BulkUpdater-Cn17jk6f.js.map