Compute and store diff summary at capture time
This commit is contained in:
@@ -615,6 +615,47 @@ function computeDetailedDiff(baseGraph, targetGraph) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compact diff stored in snapshot metadata for hover display
|
||||||
|
function computeCaptureMetaDiff(prevGraph, currGraph) {
|
||||||
|
if (!prevGraph || !currGraph) return null;
|
||||||
|
const diff = computeDetailedDiff(prevGraph, currGraph);
|
||||||
|
const result = {};
|
||||||
|
if (diff.addedNodes.length > 0)
|
||||||
|
result.added = diff.addedNodes.map(n => n.title);
|
||||||
|
if (diff.removedNodes.length > 0)
|
||||||
|
result.removed = diff.removedNodes.map(n => n.title);
|
||||||
|
// Nodes with param/property changes (ignore pure position/size changes)
|
||||||
|
const paramChanged = diff.modifiedNodes.filter(n =>
|
||||||
|
n.changes.widgetValues || n.changes.properties || n.changes.title || n.changes.mode
|
||||||
|
);
|
||||||
|
if (paramChanged.length > 0)
|
||||||
|
result.params = paramChanged.map(n => {
|
||||||
|
const count = (n.changes.widgetValues?.length ?? 0) + (n.changes.properties?.length ?? 0);
|
||||||
|
return count > 0 ? `${n.title} (${count} value${count > 1 ? "s" : ""})` : n.title;
|
||||||
|
});
|
||||||
|
if (diff.addedLinks.length > 0 || diff.removedLinks.length > 0)
|
||||||
|
result.links = { added: diff.addedLinks.length, removed: diff.removedLinks.length };
|
||||||
|
return Object.keys(result).length > 0 ? result : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatCaptureDiffLines(captureDiff) {
|
||||||
|
if (!captureDiff) return [];
|
||||||
|
const lines = [];
|
||||||
|
if (captureDiff.added?.length)
|
||||||
|
lines.push(`+ ${captureDiff.added.join(", ")}`);
|
||||||
|
if (captureDiff.removed?.length)
|
||||||
|
lines.push(`− ${captureDiff.removed.join(", ")}`);
|
||||||
|
if (captureDiff.params?.length)
|
||||||
|
lines.push(`~ ${captureDiff.params.join(", ")}`);
|
||||||
|
if (captureDiff.links) {
|
||||||
|
const parts = [];
|
||||||
|
if (captureDiff.links.added) parts.push(`+${captureDiff.links.added} link${captureDiff.links.added > 1 ? "s" : ""}`);
|
||||||
|
if (captureDiff.links.removed) parts.push(`−${captureDiff.links.removed} link${captureDiff.links.removed > 1 ? "s" : ""}`);
|
||||||
|
if (parts.length) lines.push(parts.join(", "));
|
||||||
|
}
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
// ─── SVG Graph Renderer ─────────────────────────────────────────────
|
// ─── SVG Graph Renderer ─────────────────────────────────────────────
|
||||||
|
|
||||||
const SVG_NS = "http://www.w3.org/2000/svg";
|
const SVG_NS = "http://www.w3.org/2000/svg";
|
||||||
@@ -1471,6 +1512,7 @@ async function _captureSnapshotInner(label) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const captureDiff = computeCaptureMetaDiff(prevGraph, graphData);
|
||||||
const record = {
|
const record = {
|
||||||
id: generateId(),
|
id: generateId(),
|
||||||
workflowKey,
|
workflowKey,
|
||||||
@@ -1481,6 +1523,7 @@ async function _captureSnapshotInner(label) {
|
|||||||
locked: false,
|
locked: false,
|
||||||
changeType,
|
changeType,
|
||||||
parentId,
|
parentId,
|
||||||
|
...(captureDiff ? { captureDiff } : {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -1550,6 +1593,7 @@ async function captureNodeSnapshot(label = "Node Trigger", thumbnail = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const captureDiff = computeCaptureMetaDiff(prevGraph, graphData);
|
||||||
const record = {
|
const record = {
|
||||||
id: generateId(),
|
id: generateId(),
|
||||||
workflowKey,
|
workflowKey,
|
||||||
@@ -1561,6 +1605,7 @@ async function captureNodeSnapshot(label = "Node Trigger", thumbnail = null) {
|
|||||||
source: "node",
|
source: "node",
|
||||||
changeType,
|
changeType,
|
||||||
parentId,
|
parentId,
|
||||||
|
...(captureDiff ? { captureDiff } : {}),
|
||||||
...(thumbnail ? { thumbnail } : {}),
|
...(thumbnail ? { thumbnail } : {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user